设置EditText光标颜色

EditText光标显示的颜色

一.全局设置

进入AndroidManifest文件,找到 android:theme="@style/Theme"
上面的这行代码“android:theme=”@style/Theme”,点击查看Theme的属性,
如有:
< item name=“colorAccent”>@color/colorAccent< /item>
@color/colorAccent 就是全局设置光标的颜色,修改为你对应想要的颜色即可。

二.局部设置

1.自定义颜色

在xml布局文件中的exitText中加入该属性即可:
android:textCursorDrawable="@drawable/custom"
其中**@drawable/custom**的代码如下:

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

颜色可以根据需求设置,需要注意的是android:width宽度设置,不设置光标会不显示

2.跟随文本的颜色

只需将textCursorDrawable的值设置为@null即可:
android:textCursorDrawable="@null"


版权声明:本文为m0_49241867原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。