How to remove focus from SearchView?

前端 未结 10 1500
野趣味
野趣味 2021-02-06 22:20

I want to remove focus and text from SearchView in onResume().

I tried searchView.clearFocus() but it is not working.

Thi

10条回答
  •  旧时难觅i
    2021-02-06 22:59

    You can manually hide the keyboard in onResume() function as:

    InputMethodManager imm = (InputMethodManager) context.getSystemService(context.INPUT_METHOD_SERVICE);
            View view = context.getCurrentFocus();
    
            if (view == null) {
                view = new View(context);
            }
            if (view != null) {
    
                IBinder iBinder = view.getWindowToken();
    
                 imm.hideSoftInputFromWindow(iBinder, 0);
             }
    

提交回复
热议问题