11

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>

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

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

Is there any way i can change the color of the blinking cursor with 3.0 as the target?

Thanks for helping :)

Community
  • 1
  • 1
Georg
  • 3,119
  • 2
  • 27
  • 60
  • 1
    http://stackoverflow.com/questions/7238450/set-edittext-cursor-color Please check upper link –  Feb 20 '14 at 09:35

2 Answers2

2

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

android:textCursorDrawable is the key here.

And also refer this one Vertical line using XML drawable

Community
  • 1
  • 1
1

I was trying to change the cursor color in my app which targeted API 8. I've found out that TextView uses textColor property as the cursor color. Here's a part of onDraw() defined in TextView API 8:

    int color = mCurTextColor;

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

    Layout layout = mLayout;
    int cursorcolor = color;

The cursorcolor is then used to constract an android.graphics.Path object representing the color.

If you need to change this behaviour, you're up to quite a task, you'll have to implement your own TextView.

devmiles.com
  • 9,522
  • 5
  • 30
  • 45