How to change Android EditText Cursor Color


You can change the Color of Android EditText View by creating a custom XML for the cursor,

1. Create a file custom_edit_text_cursor.xml under res/drawable folder,

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle" >
  <size
    android:width="2dip" />
  <solid
    android:color="@color/green" />
</shape>

2. Now add attribute android:textCursorDrawable to your EditText View XML,

<EditText
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top"
    android:lineSpacingExtra="10dp"
    android:textCursorDrawable="@drawable/custom_edit_text_cursor"
</EditText>

⚠️ Note: textCursorDrawable was introduced in Android SDK Level 12, hence you need to set minSDK level 12 or above for this to work! You may get a warning if you set minSDK level below API Level 12.

❗️ Attribute "textCursorDrawable" is only available in API level 12 and higher (current min is 8)