2011-12-14 68 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