Set EditText cursor color

I am having this issue where I am using the Android's Holo theme on a tablet project. However, I have a fragment on screen which has a white background. I am adding an EditText component on this fragment. I've tried to override the theme by setting the background of the Holo.Light theme resources. However, my text cursor (carat) remains white and hence, invisible on screen (I can spot it faintly in the edittext field..).

Does anyone know how I can get EditText to use a darker cursor color? I've tried setting the style of the EditText to "@android:style/Widget.Holo.Light.EditText" with no positive result.


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

Attribute "textCursorDrawable" is available in API level 12 and higher


In Layout

<EditText  
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textCursorDrawable="@drawable/color_cursor"
    />

Then create drawable xml: color_cursor

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="3dp" />
    <solid android:color="#FFFFFF"  />
</shape>

You have a white color cursor on EditText property.


It appears as if all the answers go around the bushes.

In your EditText , use the property:

android:textCursorDrawable="@drawable/black_cursor"

and add the drawable black_cursor.xml to your resources, as follows:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <size android:width="1dp" />
    <solid android:color="#000000"/>
</shape>

This is also the way to create more diverse cursors, if you need.

链接地址: http://www.djcxy.com/p/24254.html

上一篇: 停止ScrollView将焦点设置为EditText

下一篇: 设置EditText光标颜色