Alex Rivera | Logout

Change the color of the cursor of an EditText in Android across all the sdk

Asked 2012-07-17T13:25:20.120
14

I want to change the android's edittext cursor color on all devices. How do I do that?

Edit
Report

2 Answers

8

The way to get it across all platforms is as such.

1 - Open your layout.xml in your layout folder. Find the edit text and set

android:cursorVisible="true"

this will set the cursor for devices lower that os version 11

2 - Create your cursor_drawable.xml in the 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="1dp" />
    <stroke android:color="@color/black"/>
</shape>

3 - Create a folder layout-v11

4 - Copy your layout.xml into the layout-v11

5 - Find your edit text and set android:textCursorDrawable="@drawable/cursor_drawable"

This will make a cursor be shown on all devices and OS.

answered 2012-10-15T09:40:22.307
7

Assign android:textCursorDrawable attribute to @null and set android:textColor as the cursor color.

answered 2012-07-17T13:34:56.267

Your Answer