How to close a SearchView programmatically on back pressed?

后端 未结 8 1935
余生分开走
余生分开走 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:06

    Add a method to close the keyboard within onBackPressed() here is the code to hide keyboard.

    private void hideKeyboard() {
    InputMethodManager imm = (InputMethodManager) 
        getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mInputField.getWindowToken(), 0);
    }
    

提交回复
热议问题