Ritesh Kumar Singh
Ritesh Kumar Singh

Reputation: 354

How to change edit text cursor color and width in android

I'm developing a new app where i need to customise EditText cursor colour and width of cursor. Can any one please guide me.It will be appriciable. Thanks in advance.

Upvotes: 18

Views: 12741

Answers (2)

Uzair
Uzair

Reputation: 1538

Build your new drawable for cursor for example name it my_custom_cursor_drawable.xml in the drawable folder

my_custom_cursor_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle" >
<size android:width="0.5dp" />
<solid android:color="#FF0910DD"/>!--Could be any color you want
</shape>

The EditBox where you want this custom cursor set the property as

 android:textCursorDrawable="@drawable/cursor_drawable"

Thats it !! improvise if need be. Any drawable , any shape etc...

Upvotes: 35

Paresh Mayani
Paresh Mayani

Reputation: 128428

You can define a custom drawable for the EditText Cursor and use it for EditText using android:textCursorDrawable.

Upvotes: 2

Related Questions