Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

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 the screen which has a white background. I am adding an EditText component to this fragment. I've tried to override the theme by setting the background of the Holo.Light theme resources. However, my text cursor (caret) remains white and hence, invisible on-screen (I can spot it faintly in the edit text field..).

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

3 Answers

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


Then create drawalble xml: color_cursor

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="url of android schema" >
<size android:width="3dp" />
<solid android:color="#FFFFFF" />

You have a white color cursor on the EditText property.
I found the answer :)

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>

android:textCursorDrawable is the key here.

Login / Signup to Answer the Question.