改变一个EditText的光标颜色的Andr​​oid 3.0光标、颜色、EditText、oid

2023-09-06 14:35:44 作者:23.爱里全是难过

我必须有一个EditText在我的背景为白色的应用程序。我在theme.xml文件中这样做

I have to have an EditText in my application with a white background. I did this in my theme.xml file

<style name="myEditText" parent="@android:style/Widget.EditText">
  <item name="android:background">#ffffffff</item>
  <item name="android:textColor">#ff000000</item>
</style>

现在的问题是,光标依然是白色的,所以无法看到。 我做了一些谷歌搜索,发现这个问题,在这里计算器: 设置的EditText光标颜色

The problem now is that the cursor is still white and therefore not visible. I did some googling and found this question here on StackOverflow: Set EditText cursor color

它这样做的方式出现的安卓textCursorDrawable 键。但这个关键似乎是只提供了3.2的目标。但是,我们的客户想要一个3.0的目标,我找不到任何其他的解决办法...

The way it's done there is the android:textCursorDrawable key. But this key does seem to be only available with a 3.2 target. But our clients wants a 3.0 target and I could not find any other solution...

有什么办法,我可以用3.0改变闪烁光标的颜色作为目标?

感谢您的帮助:)

推荐答案

我找到了答案:)

我已经设置了主题的EDITTEXT风格:

I've set the Theme's editText style to:

<item name="android:editTextStyle">@style/myEditText</item>

然后我用下面的绘制将光标设置:

Then I've used the following drawable to set the cursor:

<style name="myEditText" parent="@android:style/Widget.Holo.Light.EditText"> 
<item name="android:background">@android:drawable/editbox_background_normal</item> 
<item name="android:textCursorDrawable">@android:drawable/my_cursor_drawable</item> 
<item name="android:height">40sp</item> </style>

机器人:textCursorDrawable 的关键是这里

和也提到这一 的Andr​​oid垂直线XML