Search code examples
androidandroid-studiocolorsstylessearchview

Android SearchView Not Applying Style


My android.support.v7.widget.SearchView that I added into my Activity (not in the toolbar) doesn't seem to fully apply the style I created.

This is the code for the SearchView itself in which I reference AppTheme.SearchView as the style it should apply.

<android.support.v7.widget.SearchView
                android:id="@+id/search_dashboard"
                style="@style/AppTheme.SearchView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/color_primary"
                android:layout_below="@id/toolbar_dashboard"
                android:elevation="@dimen/toolbar_elevation" />

This is the code for the style:

<style name="AppTheme.SearchView" parent="Widget.AppCompat.Light.SearchView">

    <item name="android:colorPrimary">@android:color/white</item>
    <item name="android:colorPrimaryDark">@android:color/white</item>
    <item name="android:textColorPrimary">@android:color/white</item>
    <item name="android:textColorSecondary">@android:color/white</item>
    <item name="android:textColor">@android:color/white</item>

    <!-- Gets rid of the search icon when the SearchView is expanded -->
    <item name="searchHintIcon">@null</item>
    <!-- The hint text that appears when the user has not typed anything -->
    <item name="queryHint">Test 1</item>
</style>

I'm trying to set the color of the Icons, and all the Text to white. When I execute the app I get this result:

enter image description here enter image description here

You can see that I apply the queryHint of the style but it doesn't change the colors. I think that the editTextColor used, is defined in my default app Style as

<item name="android:textColorPrimary">@color/color_text_primary</item>

and

<color name="color_text_primary">#344d93</color>

How can this occur if I set other colors in the specific style?


Solution

  • For customization you can use android:theme="@style/AppTheme.SearchView" or dynamically using this code https://gist.github.com/jaredrummler/c408c9d897fd92d5d116