Auto Collapse ActionBar SearchView on Soft Keyboard close

后端 未结 11 1134
遥遥无期
遥遥无期 2020-12-07 20:30

I am currently using an ActionBar menu item to display a SearchView in the action bar. When the search menu item is expanded the soft keyboard is displayed which is what I

11条回答
  •  醉酒成梦
    2020-12-07 20:55

    This is what I did for making the keyboard disappear. You can try to see if this works for you. I set the searchView to invisible and then to visible again.

        //set query change listener
         searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener(){
            @Override
            public boolean onQueryTextChange(String newText) {
                // TODO Auto-generated method stub
                return false;
            }
    
            @Override
            public boolean onQueryTextSubmit(String query) {
                /**
                 * hides and then unhides search tab to make sure keyboard disappears when query is submitted
                 */
                      searchView.setVisibility(View.INVISIBLE);
                      searchView.setVisibility(View.VISIBLE);
                return false;
            }
    
         });
    

提交回复
热议问题