又一次做應用,發現EditText沒有顯示光標,借鑒了網上的方法,發現是因為光標是白色的,與背景一樣造成的,這里記錄一下如何設置EditText等的光標顏色:
需要在布局文件中指定androd:textCursorDrawable,如果需要設置成與字體一樣的顏色,改屬性設置為“@null”即可,如果需要自定義顏色,需要自定義一個drawable文件,例如:在drawable下窗井my_cursor.xml,內容如下
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#000080" /> <size android:width="1dp"/> </shape>
然后,設置android:textCursorDrawable="@drawable/my_cursor",光標顏色就可以改變為指定顏色。