1

I know this topic has been asked previously but most of the answers provide a programatic solution which is not very up to date.

I have a SearchView inside Toolbar, I need to modify it's appearance a bit, here's my style file

<resources>
    <style name="Theme.XYZ" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#29abbd</item>
        <item name="colorPrimaryDark">#00838f</item>
        <item name="colorAccent">#29abbd</item>
        <item name="colorButtonNormal">#29abbd</item>
        <item name="android:windowBackground">@color/window_background</item>
        <item name="searchViewStyle">@style/Theme.XYZ.SearchView</item>
    </style>


    <style name="Theme.XYZ.SearchView" parent="Widget.AppCompat.Light.SearchView">
        <item name="closeIcon">@drawable/ic_launcher</item>
        <item name="colorAccent">#ffffff</item>
    </style>

</resources>

This does not work, the SearchView is not assigned with the custom close icon and the colorAccent is the color of the main theme.

Your help is appreciated.

Aviran
  • 5,160
  • 7
  • 44
  • 76
  • What color should be changed? The textcolor, background or something else? – Thomas R. Oct 13 '15 at 06:56
  • The cursor's color, which is controlled by the colorAccent. – Aviran Oct 13 '15 at 06:57
  • Maybe it is because you are declaring two parents. Can you change the searchview style name to `MySearchViewStyle`? And test if the close icon changes? And I think the cursor color is controlled by another field and cannot be overruled like you do, I guess. Give it a try :) – Thomas R. Oct 13 '15 at 07:04
  • I've tried, the icon does not change. – Aviran Oct 13 '15 at 07:08
  • Do you apply the theme to the activity where the searchview should be displayed? Regarding the cursor you may have a look here: http://stackoverflow.com/questions/15527420/custom-cursor-color-in-searchview – Thomas R. Oct 13 '15 at 07:10
  • Yes, the theme itself (Theme.XYZ) is being applied, thanks, will have a look. – Aviran Oct 13 '15 at 07:12
  • Thanks, I got it to work with using Widget.AppCompat.Light.AutoCompleteTextView instead if Widget.AppCompat.Light.SearchView and using android:textCursorDrawable. Put it as an answer and I'll accept. – Aviran Oct 13 '15 at 07:22
  • Check this once http://stackoverflow.com/questions/27730253/how-to-style-the-cursor-color-of-searchview-under-appcompat – Prasad Oct 13 '15 at 07:25

1 Answers1

0

I'm posting here my solution, although it defines a style to AutoCompleteTextView instead of SearchView directly

<style name="Theme.XYZ" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#29abbd</item>
        <item name="colorPrimaryDark">#00838f</item>
        <item name="colorAccent">#29abbd</item>
        <item name="colorButtonNormal">#29abbd</item>
        <item name="android:windowBackground">@color/window_background</item>
        <item name="autoCompleteTextViewStyle">@style/XYZSearchView</item>


    </style>


    <style name="XYZSearchView" parent="Widget.AppCompat.Light.AutoCompleteTextView">
        <item name="android:textCursorDrawable">@drawable/white_cursor</item>
    </style>
Aviran
  • 5,160
  • 7
  • 44
  • 76