改变EditText光标宽度、颜色、高度增加用户体验

时间:2021-10-07 11:52:34

改变光标粗细、颜色,创建一个Drawable Resource File,再在XML的EditText中设置android:textCursorDrawable="@Drawable/xxxxx":

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!--这里设置光标宽度(粗细)-->
<size android:width="3dp" />
<!--这里设置光标颜色-->
<solid android:color="#000000" />
</shape>
改变Edittext的光标高度,一般光标高度都会占满一个Edittext的高度,有时候减少光标高度来增加用户体验原理是利用padding增加内边距来减少光标跟字体的高度,这里只需要在XML中的EditText中添加android:padding=“xx”就可以了. 


最后说一下EditText输入时宽度随着输入变大,这时候可以设置:

android:layout_width="0dp"
android:layout_weight="10"
layout_weight的大小自己决定,但是layout_width一定要等于0dp.