6

I was trying to customize Android edittext cursor. I found many solution using android:textCursorDrawable=""on Google and StackOverflow. But it is available from API 12.

<EditText
    android:id="@+id/edittext"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:text="Android"
    android:textCursorDrawable="@drawable/my_cursor_drawable" />

I want to do that from API 8. So is it possible to change edittext cursor color in < API 12 ?

ktn
  • 131
  • 1
  • 5

1 Answers1

1

You could try this(with java reflection),

try {
    Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
    f.setAccessible(true);
    f.set(et1, R.drawable.ic_launcher);
} catch (Exception ignored) {}

reference :How to Change programatically Edittext Cursor Color in android?

Community
  • 1
  • 1
fchristysen
  • 208
  • 1
  • 10