How to check visibility of software keyboard in Android?

前端 未结 30 4550
半阙折子戏
半阙折子戏 2020-11-21 04:43

I need to do a very simple thing - find out if the software keyboard is shown. Is this possible in Android?

30条回答
  •  忘掉有多难
    2020-11-21 05:21

    The idea is, if you need to hide your keyboard and check soft input state at the same time, use the following solution:

    public boolean hideSoftInput() {
        InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
        return imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0);
    }
    

    This method returns true if keyboard was shown before hiding.

提交回复
热议问题