| 本帖最后由 liu 于 2018-12-5 15:08 编辑 
 自定义EditText光标颜色
 
 
  
 
 android:textCursorDrawable,使用这个属性用来控制光标颜色
 
 1、首先在res/drawable下新建一个xml文件:
 
 cursor_color.xml
 
 [XML] 纯文本查看 复制代码 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!-- 颜色  这里设置的是黑色 -->
    <solid android:color="#000000" />
    <!-- 光标宽度 -->
    <size android:width="2dp" />
</shape>
 2、在要设置的EditText中引用cursor_color.xml
 
 activity_main.xml:
 
 [XML] 纯文本查看 复制代码 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp">
    <EditText
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:textCursorDrawable="@drawable/cursor_color" />
</LinearLayout>
效果如下图所示:
 
 
   
 
 
 
 
 |