TextView

    xiaoxiao2021-03-25  117

    1.android:textIsSelectable=”true”是否可以选择(可以复制)


    2.android:selectAllOnFocus=”true”是否获取焦点后全部选中


    3.android:textColorHighlight=”@color/colorAccent”设置选中后的高亮颜色


    4.setAutoLinkMask(int mask)对应xml中的android:autoLink,用于声明TextView实例可识别的链接类型。

    5.setLinkTextColor(@ColorInt int color)对应xml中的android:textColorLink,用于设置TextView实例中链接的颜色。

    6.setLinksClickable(boolean whether)对应xml中的android:linksClickable,用于设置TextView实例中的链接是否可点击/点击是否执行对应动作。


    7.setTextScaleX(float size)对应xml中的android:textScaleX,用于设置TextView实例中文字横向拉伸倍数。


    8.setMinLines(int minlines)对应xml中的android:minLines,用于设置TextView最小高度为指定行高度。


    9.setMaxLines(int maxlines)对应xml中的android:maxLines,用于设置TextView最大高度为指定行高度。


    10.setLines(int lines)对应xml中的android:lines,用于设置TextView精确高度为指定行高度。


    11.android:password 用于设置TextView中内容是否为明文。


    12.setShadowLayer(float radius, float dx, float dy, int color)

    对应xml中的android:shadowRadius,android:shadowDx,android:shadowDy,android:shadowColor,用于设置文字阴影。


    13.setEllipsize(TextUtils.TruncateAt where)对应xml中的android:ellipsize,用于文字省略样式设置。


    14.setCompoundDrawablePadding(int pad)对应xml中的android:drawablePadding,用于设置TextView中文字与四周drawable的间距。


    15.setCompoundDrawableTintList(@Nullable ColorStateList tint)对应xml中的android:drawableTint,用于设置TextView四周drawable的着色

    示例: 经试验在Android 4.22上,以下方法无效: DrawableCompat.setTint(d1,Color.RED); DrawableCompat.setTintMode(d1, PorterDuff.Mode.SRC_ATOP); 正确做法: Drawable d1 = getResources().getDrawable(R.mipmap.i1).mutate(); d1.setBounds(0,0,64,64); d1.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP); Drawable d2 = getResources().getDrawable(R.mipmap.i2).mutate(); d2.setBounds(0,0,64,64); d2.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP); Drawable[] drawables = tv_drawableTint.getCompoundDrawables(); drawables[0] = d1; drawables[2] = d2; tv_drawableTint.setCompoundDrawables(drawables[0],drawables[1],drawables[2],drawables[3]);

    16.setLineSpacing(float add, float mult)对应xml中的android:lineSpacingMultiplier和android:lineSpacingExtra,用于设置多行TextView中单行高度。

    android:lineSpacingMultiplier="1.0" android:lineSpacingExtra="32dp"

    17.setLetterSpacing(float letterSpacing)对应xml中的android:letterSpacing,用于设置文本的字符间距。(但本人测试没有效果)


    18.setAllCaps(boolean allCaps)对应xml中的android:textAllCaps,用于设置TextView中的字符是否全部显示为大写形式。


    19.setTransformationMethod(TransformationMethod method)用于设置TextView展示内容与实际内容之间的转换规则。


    20.setTextSize(int unit, float size)用于设置TextView实例的文字尺寸为指定单位unit的指定值size。

    HideReturnsTransformationMethod隐藏回车

    SingleLineTransformationMethod不能用换行回车

    PasswordTransformationMethod密码类型

    ReplacementTransformationMethod抽象类,前面两个都是继承于这个抽象类,很明显就是替换,我们可以自己去继承这个类实现自己的TransformationMethod

    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else { editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); } } });
    转载请注明原文地址: https://ju.6miu.com/read-17832.html

    最新回复(0)