I am having this issue where I am using the Android's Holo theme on a tablet project. However, I have a fragment on screen which has a white background. I am adding an EditText
component on this fragment. I've tried to override the theme by setting the background of the Holo.Light theme resources. However, my text cursor (carat) remains white and hence, invisible on screen (I can spot it faintly in the edittext field..).
Does anyone know how I can get EditText to use a darker cursor color? I've tried setting the style of the EditText to "@android:style/Widget.Holo.Light.EditText"
with no positive result.
For anyone that needs to set the
EditText
cursor color dynamically, below you will find two ways to achieve this.First, create your cursor drawable:
Set the cursor drawable resource id to the drawable you created (https://github.com/android/platform_frameworks_base/blob/kitkat-release/core/java/android/widget/TextView.java#L562-564">source)):
To just change the color of the default cursor drawable, you can use the following method:
The only valid answer should be to change the theme of the activity:
<item name="colorAccent">#000000</item>
You should not use theandroid:textCursorDrawable
to@null
because this only concerns the cursor itself but not the pin below the cursor if you want to drag that cursor. The theming solution is the most serious one.editcolor.xml
android:textCursorDrawable="@drawable/editcolor"
In xml file set color code of
edittext
background colorchange t he color of colorAccent in styles.xm, that's it simple
In Layout
Then create drawable xml: color_cursor
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:and add the drawable
black_cursor.xml
to your resources, as follows:This is also the way to create more diverse cursors, if you need.