I want to change the color of the blinking cursor in a SearchView in the Actionbar (I'm using Actionbar Sherlock for compatibility). Until now I've managed to change the color of the cursor for a EditText element. This SO post helped me to accomplish that and the style I'm using for the EditText looks like this:
<style name="CustomTheme" parent="Theme.Sherlock.Light">
<item name="android:editTextStyle">@style/edittext_style</item>
</style>
<style name="edittext_style" parent="@android:style/Widget.EditText">
<item name="android:textCursorDrawable">@drawable/red_cursor</item>
</style>
The red cursor looks like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient android:startColor="@color/darkRed"
android:endColor="@color/darkRed" />
<size android:width="1dp" />
</shape>
I did take a look at the implementation of the SearchView widget and as I though it uses an AutoCompleteTextView for the text input. Since the AutoCompleteTextView is derived from the EditText widget, I don't really understand why the style is working for the EditText but not for the AutoCompleteTextView (and therefore for the SearchView).
Has anyone managed to change the color of the cursor in the SearchView widget?
I just found a solution that works. I replaces the
<style name="edittext_style" parent="@android:style/Widget.EditText">
<item name="android:textCursorDrawable">@drawable/red_cursor</item>
</style>
with
<style name="SearchViewStyle" parent="Widget.Sherlock.Light.SearchAutoCompleteTextView">
<item name="android:textCursorDrawable">@drawable/red_cursor</item>
</style>
and modified my theme so that it looks like this:
<style name="CustomTheme" parent="Theme.Sherlock.Light">
...
<item name="searchAutoCompleteTextView">@style/SearchViewStyle</item>
...
</style>
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