Visible keyboard detection?

Is it possible to determine whether the keyboard is displayed on the screen or not?

thanks

+6
source share
3 answers

I think this thread should answer your question. To summarize, you can give your root activity type an identifier, such as "@ + id / activityRoot", and then connect the GlobalLayoutListener to the ViewTreeObserver for this view. In the listener, you check the visibility of the keyboard, for example:

final View activityRootView = findViewById(R.id.activityRoot); activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (getResources().getConfiguration().keyboardHidden == Configuration.KEYBOARDHIDDEN_NO) { // Check if keyboard is not hidden // ... do something here } } }); 

This is a combination of @Reuben_Scratton and @Yogesh answers in the stream above.

UPDATE: Please note that the documentation for keyboardHidden indicates that ALWAYS will return Configuration.KEYBOARDHIDDEN_YES if the device has a hard keyboard (for example, Motorola Droid 1 and 2).

+3
source

try this or this workaround, since it is not possible in a "simple" call to the sdk method

+1
source

You can try something like that:

 InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); boolean showingKeyboard = imm.isActive(); 

Hope this helps!

EDIT:

Another option is to simply make the keyboard open or close, depending on what you want the user to see. This will lead to more predictable behavior and is likely to improve user experience.

-3
source

Source: https://habr.com/ru/post/903409/


All Articles