Set EditText cursor color
Setting the android:textCursorDrawable
attribute to @null
should result in the use of android:textColor
as the cursor color.
Attribute "textCursorDrawable" is available in API level 12 and higher
There is a new way to change cursor color in latest Appcompact
v21
Just change colorAccent
in style like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#088FC9</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#088FC9</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<!-- THIS IS WHAT YOU'RE LOOKING FOR -->
<item name="colorAccent">#0091BC</item>
</style>
Then apply this style on your app theme or activities.
Update: this way only works on API 21+
Update 2: I'm not sure the minimum android version that it can work.
Tested by android version:
2.3.7 - didn't work
4.4.4 - worked
5.0 - worked
5.1 - worked
In Layout
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textCursorDrawable="@drawable/color_cursor"
/>
Then create drawalble xml: color_cursor
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size android:width="3dp" />
<solid android:color="#FFFFFF" />
</shape>
You have a white color cursor on EditText property.
It appears as if all the answers go around the bushes.
In your EditText
, use the property:
android:textCursorDrawable="@drawable/black_cursor"
and add the drawable black_cursor.xml
to your resources, as follows:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<size android:width="1dp" />
<solid android:color="#000000"/>
</shape>
This is also the way to create more diverse cursors, if you need.