TextView

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());  
        }  
    }  
}); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值