How do I detect if software keyboard is visible on Android Device or not?

前端 未结 30 1875
情书的邮戳
情书的邮戳 2020-11-22 10:59

Is there a way in Android to detect if the software (a.k.a. \"soft\") keyboard is visible on screen?

30条回答
  •  轮回少年
    2020-11-22 11:38

    I created a simple class that can be used for this: https://github.com/ravindu1024/android-keyboardlistener. Just copy it in to your project and use as follows:

    KeyboardUtils.addKeyboardToggleListener(this, new KeyboardUtils.SoftKeyboardToggleListener()
    {
        @Override
        public void onToggleSoftKeyboard(boolean isVisible)
        {
            Log.d("keyboard", "keyboard visible: "+isVisible);
        }
    });
    

提交回复
热议问题