Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change editext cursor color in API 12

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 ?

like image 600
ktn Avatar asked Aug 22 '13 07:08

ktn


People also ask

What is textCursorDrawable?

Custom cursor color EditText has an attribute: android:textCursorDrawable, which is used to set the cursor style.


1 Answers

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?

like image 82
fchristysen Avatar answered Sep 28 '22 02:09

fchristysen