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

前端 未结 30 2080
情书的邮戳
情书的邮戳 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:52

    I did this as follows, but its relevet only if your goal is to close / open the keyboad.

    close example: (checking if keyboard already closed, if not - closing)

    imm.showSoftInput(etSearch, InputMethodManager.HIDE_IMPLICIT_ONLY, new ResultReceiver(null) {
                        @Override
                        protected void onReceiveResult(int resultCode, Bundle resultData) {
                            super.onReceiveResult(resultCode, resultData);
                            if (resultCode != InputMethodManager.RESULT_UNCHANGED_HIDDEN)
                                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                        }
                    });
    

提交回复
热议问题