How to close a SearchView programmatically on back pressed?

后端 未结 8 1929
余生分开走
余生分开走 2021-01-07 07:39

I have the same question which I found here which I will re-iterate because the solution is not 100% exactly what I need:

I currently have a SearchVie

相关标签:
8条回答
  • 2021-01-07 08:27

    An interesting answer!

     @Override
        public void onBackPressed() {
          if (!searchView.isIconified()) {
            searchView.setIconified(true);
            searchView.setIconified(true);
          } else {
            super.onBackPressed();
          }
        }
    
    0 讨论(0)
  • 2021-01-07 08:29

    Instead of hide soft keyboard manually, try clearFocus() method

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