Stack Overflow archive
17 score

change edittext cursor color

score
17
question views
79.1K
license
CC BY-SA 3.0

Here is, what I think, a better solution than what @Adem posted.

Java:

java
try {
    // https://github.com/android/platform_frameworks_base/blob/kitkat-release/core/java/android/widget/TextView.java#L562-564
    Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
    f.setAccessible(true);
    f.set(yourEditText, R.drawable.cursor);
} catch (Exception ignored) {
}

XML:

xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#ff000000" />

    <size android:width="1dp" />

</shape>

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.