How to completely collapse a SearchView after an item selected?

后端 未结 10 1911
萌比男神i
萌比男神i 2021-01-31 17:35

I\'ve been struggling with this for weeks.. I have a global search that offers up a custom listview with suggestions as a user types. When a user selects an option, I want the s

相关标签:
10条回答
  • 2021-01-31 17:36

    If you're using Toolbar (android.support.v7.widget.Toolbar) and the corresponding SearchView (android.support.v7.widget.SearchView) with it, this works:

        searchView.setQuery("", false);
        searchView.clearFocus();
        searchView.setIconified(true);
    
    0 讨论(0)
  • 2021-01-31 17:36
    searchView.setIconified(true); // Call this twice
    searchView.setIconified(true);
    

    It works for me.

    0 讨论(0)
  • 2021-01-31 17:41

    This worked for me and it also closed the keyboard by Default

    MenuItemCompat.collapseActionView(menuItem);
    
    0 讨论(0)
  • 2021-01-31 17:43

    Instead of calling _searchView.onActionViewCollapsed() call menuItem.collapseActionView() where _searchView = menuItem.getActionView().

    0 讨论(0)
  • 2021-01-31 17:44

    Found it. The call should be _searchView.onActionViewCollapsed(). Why on earth you call a "listener" style method (ie, one that begins with 'on') is beyond me.

    0 讨论(0)
  • 2021-01-31 17:48

    You should clear the search, remove the focus and then call:

    searchView.setIconified(true);
    
    0 讨论(0)
提交回复
热议问题