2011-12-14 67 views
11

我必须在我的应用程序中有一个带有白色背景的EditText。我这样做,我theme.xml文件更改Android 3.0中EditText的光标颜色

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

现在的问题是,光标仍然是白色的,所以无法看到。 我做了一些谷歌搜索,并在这里找到这个问题在计算器上: Set EditText cursor color

它的完成还有就是android:textCursorDrawable键的方式。但是这个关键似乎只对3.2目标有效。但我们的客户想要一个3.0的目标,我找不到任何其他的解决办法...

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

感谢您的帮助:)

+1

http://stackoverflow.com/questions/7238450/set-edittext-cursor-color 请检查上部连杆 – 2014-02-20 09:35:29

回答

2

我找到了答案:)

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

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

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

<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> 

android:textCursorDrawable是这里的关键。

而且还指这一个 Vertical line using XML drawable

+8

对不起,你可能没看过这个问题。 `testCursorDrawable`在android 3.0中不可用 – 2012-03-01 15:37:17

1

我试图改变我的应用程序,它有针对性的API 8.我已经发现了TextView使用textColor属性作为光标颜色光标颜色。下面是在TextView API 8中定义的onDraw()一部分:

int color = mCurTextColor; 

    if (mLayout == null) { 
     assumeLayout(); 
    } 

    Layout layout = mLayout; 
    int cursorcolor = color; 

cursorcolor然后用于建设工程代表颜色的android.graphics.Path对象。

如果你需要改变这种行为,你完成了一项任务,你必须实现自己的TextView