Programmatically Hide Soft Keyboard in ViewPager.OnPageChangeListener onPageSelected()?

后端 未结 5 1152
醉酒成梦
醉酒成梦 2021-02-02 09:39

I have a ViewPager + ActionBar with tabs. I want to make the soft keyboard hide when I \"swipe\" to another tab but I can\'t figure out how.

I\'ve passed in my Activity

5条回答
  •  天命终不由人
    2021-02-02 10:36

    Common way:

    private void hideVirturalKeyboard(){
    View v = getCurrentFocus();
    if (v != null && v instanceof EditText) {
    InputMethodManager mgr = (InputMethodManager)(v.getContext().getSystemService(Context.INPUT_METHOD_SERVIC
    E));
    mgr.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }
    } 
    

提交回复
热议问题