这个问题主要出现在当在Android Manifest文件中设置android:minSdkVersion或android:targetSdkVersion为13或更高的数值后,原因是因为系统默认的主题所致,所以要进行特别的定义。

通过以下方法来解决:

android:textCursorDrawable="@null"
 

这样会使光标的颜色与文字颜色的属性一致

另外也可以用自定义的图片资源,但好像在4.2的系统上无效,设置为null是OK的~

这个属性在低版本的系统上会被忽略,不用担心没有这个属性会造成崩溃。


下面是stackoverflow上的讨论:

http://stackoverflow.com/questions/7238450/set-edittext-cursor-color/9165217#9165217



56
down vote accepted

Setting the android:textCursorDrawable attribute to @null should result in the use ofandroid:textColor as the cursor color.

share | improve this answer
 
1  
oh man that is SO much more efficient than conjuring up a drawable for the cursor to be black!! I love Android to death but this is such an incredibly bad default behavior... someone really needs to be smacked for it. –  Dr.Dredel  Mar 13 '12 at 21:14
4  
android 3.2 and above .. sucks –  Blundell  May 21 '12 at 8:40
 
Although if you target >3.2 in your manifest you can use it and it will be ignored for lower versions –  Blundell  Aug 8 '12 at 8:07
 
in fact I have just noticed that JellyBean 4.2 does not show the cursor if you use the drawable cursor option ! @null is the way to go! –  Aiden Fry  Nov 26 '12 at 16:39


Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐