EditText改变光标颜色

以下方法二为单一edittext改变颜色,一般程序整体风格固定,按方法一执行即可。

1.改变EditText的背景色以及光标的颜色,我们可以直接改变colorAccent的颜色,这也是其中的一个方法 


2.设置android:backgroundTint="@color/color1"来改变EditText的背景色,现在我们得到的效果图的这样的: 
 
可是EditText光标的颜色怎么设置呢? 
首先我们创建shape_edittext_cursor.xml

 

 

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="2dp" />
    <solid android:color="@color/color1" />
</shape>  

并通过android:textCursorDrawable="@drawable/shape_edittext_cursor"来引用即可,效果图如下: 


android:textCursorDrawable 这个属性是用来控制光标颜色的,如果我们想设置EditView的光标颜色和text color一样,则设置android:textCursorDrawable="@null",”@null”的作用是让光标颜色和text color一样

 

说到这里,如果隐藏Edittext闪烁光标呢,就设置android:cursorVisible="false"就行了。


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值