Right now, I can change the cursor drawable through reflection and using property android:textCursorDrawable. I looked at the TextView code, and its actually reading the drawables from Resources.Theme. I'm wondering if its possible and how to change it by creating a custom theme in styles.xml?
final Resources.Theme theme = context.getTheme();
/*
* Look the appearance up without checking first if it exists because
* almost every TextView has one and it greatly simplifies the logic
* to be able to parse the appearance first and then let specific tags
* for this View override it.
*/
TypedArray a = theme.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.TextViewAppearance, defStyleAttr, defStyleRes);
In your layout do the following :
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textCursorDrawable="@drawable/cursor_color"/>
Then create drawalble cursor_color.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size android:width="2dp" />
<solid android:color="#FFFFFF"/> // Set your required color code for your cursor color
</shape>
Hope this will help you
Edittext has an attribute called android:textCursorDrawable , set this attribute to @null now you can set any desired color to android:textColor, this will result in your cursor color change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With