How to dismiss keyboard in Android SearchView?

后端 未结 15 1389
萌比男神i
萌比男神i 2020-12-05 06:27

I have a searchView in the ActionBar. I want to dismiss the keyboard when the user is done with input. I have the following queryTextListener on the searchView



        
15条回答
  •  Happy的楠姐
    2020-12-05 06:54

    Somehow it works if you call

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
    

    and then

    otherWidget.requestFocus();
    

提交回复
热议问题