ActionBar always expanded SearchView with the icon inside

前端 未结 3 1189
不知归路
不知归路 2021-01-14 13:37

I have an ActionBar with a SearchView.

I want the search view to always be \"open\" (expanded). Doing that is possible using

mSearchView.setIconifie         


        
相关标签:
3条回答
  • 2021-01-14 14:11

    I was able to solve this issue by changing my XML from

    <item android:id="@+id/search"
    android:icon="@drawable/my_icon"
    app:showAsAction="always|collapseActionView"
    app:actionViewClass="android.support.v7.widget.SearchView" />
    

    to

    <item android:id="@+id/search"
    android:icon="@drawable/my_icon"
    app:showAsAction="always"
    app:actionViewClass="android.support.v7.widget.SearchView" />
    
    0 讨论(0)
  • 2021-01-14 14:22

    You can just intercept OnClose event:

    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            return true;
        }
    });
    
    0 讨论(0)
  • 2021-01-14 14:38

    Always show/expand search box on an action bar

    Its a 2 steps solution,

    1.public void onCreateOptionsMenu(M... ... searchView.setIconifiedByDefault(false); }

    2. In the menu xml file, make sure android:showAsAction="always" is set

    <item    
            android:id="@+id/grid_default_search"
            android:icon="@android:drawable/ic_menu_search"
            android:title="search"
            android:showAsAction="always"
            android:actionViewClass="android.widget.SearchView"
        />
    
    0 讨论(0)
提交回复
热议问题