? ? 今日碰到關(guān)于edittext項(xiàng)目中自定義光標(biāo)的一個bug,總結(jié)下:
一. 自定義光標(biāo)樣式
- 在drawable目錄下自定義光標(biāo)文件(一般為shape文件)
比如以下文件為:text_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="2dp" />
<solid android:color="@color/text_cursor_color" />
</shape>
2.在xml 中給edittext設(shè)置屬性
android:textCursorDrawable="@drawable/text_cursor"
二 . 設(shè)置光標(biāo)位置
設(shè)置光標(biāo)位置主要是通過edittext的gravity屬性實(shí)現(xiàn)的
android:gravity="left" //光標(biāo)位于最開始位置
android:gravity="center" //光標(biāo)位于中間位置