Android开发中如何自定义光标颜色
在 res/drawable 目录下新建光标样式文件 my_cursor.xml,自定义光标样式如下:
```
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="2dp" />
<solid android:color="@color/black"/>
</shape>
```
如果只是修改单个edittext的光标样式,在edittext里添加textCursorDrawable属性:
```
android:textCursorDrawable="@drawable/my_cursor"
```
如果希望整个项目都使用自定义的光标文件,修改样式文件,在样式文件中添加android:textCursorDrawable:
```
<style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="android:textCursorDrawable">@drawable/my_cursor</item>
...
</style>
```
我的笔记