Search code examples
androidsearchviewandroid-5.0-lollipopmaterial-design

Style a SearchView widget using support library v21


Chris Banes mentioned here that the AppCompat library now has Lollipop's updated SearchView API. I am following the instructions straight from the blog post, but I don't see any effect.

Below is a snippet from my values/styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/color_primary</item>

    <item name="searchViewStyle">@style/CustomSearchViewStyle</item>
</style>
<style name="CustomSearchViewStyle" parent="Widget.AppCompat.SearchView">
    <item name="queryBackground">@color/orange</item>
    <item name="searchIcon">@drawable/test</item>
</style>

Solution

  • I was using android.widget.SearchView instead of android.support.v7.widget.SearchView. I am guessing that only the android:* styles work with android.widget.SearchView.