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)






Recent Posts:
Hello there!,

You are using AdBlocker!

I am an independent developer trying to help fellow developers and students to resolve issues faced on a day-to-day basis, we 'Code to Care' . There is a lot of expenses involved in hosting and managing a website that's the reason we have ads.

A humble request to you to disable adBlocker on Code2care.org and support us pay our bills.

Thanks,
Cod2ecare - Line's of code for change.

To see contents reload page after unblocking
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.