Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 447
theblang Avatar asked Oct 21 '14 16:10

theblang


People also ask

How do I use search view?

Android SearchView provides user interface to search query submitted over search provider. SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class.

How do I expand SearchView?

To make the SearchView expanded by default, call setIconifiedByDefault(false) on it when you initialise it (e.g. in onCreateOptionsMenu(..) or onPrepareOptionsMenu(..) ). I've found in most cases this will give it focus automatically, but if not simply call requestFocus() on it too.


1 Answers

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.

like image 198
theblang Avatar answered Nov 14 '22 23:11

theblang