在EditText中插入下面语句,增加一个属性,就可以设置输入框中光标的颜色
android:textCursorDrawable="@drawable/bg_cursor"
bg_cursor.xml的代码如下
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 输入框的光标的粗细 -->
<size android:width="0.5dp" />
<!-- 输入框的光标的颜色,本颜色为黑色 -->
<solid android:color="@color/color_333333" />
</shape>
经过测试发现大部分手机的光标颜色通过上述代码都可以改变,但发现华为手机的输入框光标颜色还是系统自带颜色,设置的颜色无效果。那么还需要在EditText中加入下面的语句,才能使得华为手机的输入框光标颜色生效。
android:imeOptions="normal"