Android学习——设置EditText的hint字体大小和光标颜色

转自:https://blog.csdn.net/janronehoo/article/details/88818483

由于默认的hint字体比较丑,我们经常需要自己去设置字体大小和光标样式

/**
     * 设置 hint字体大小
     * @param editText 输入控件
     * @param hintText hint的文本内容
     * @param textSize hint的文本的文字大小(以dp为单位设置即可)
     */
    public static void setHintTextSize(EditText editText, String hintText, int textSize) {
        // 新建一个可以添加属性的文本对象
        SpannableString ss = new SpannableString(hintText);
        // 新建一个属性对象,设置文字的大小
        AbsoluteSizeSpan ass = new AbsoluteSizeSpan(textSize, true);
        // 附加属性到文本
        ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
 
        // 设置hint
        editText.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
    }
光标的颜色
1.设置为null,让光标和字体的颜色一样

android:textCursorDrawable="@null" 
2.自定义光标颜色,定义一个资源文件,可以设置光标的颜色和粗细。

android:textCursorDrawable="@drawable/color_cursor" 
 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >  
     <size android:width="2dp" />  
    <solid android:color="#FF4081"  />  
</shape>
收工!!!!!!
--------------------- 
作者:janronehoo 
来源:CSDN 
原文:https://blog.csdn.net/janronehoo/article/details/88818483 
版权声明:本文为博主原创文章,转载请附上博文链接!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值