Is it possible to detect whether a keyboard is visible on the screen or not?
Thanks
I think this thread should answer your question. To summarize, you can give your activity's root view an id, such as "@+id/activityRoot", and then hook a GlobalLayoutListener into the ViewTreeObserver for that view. In the listener is where you check the visibility of the keyboard, like so:
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's answers in the above thread.
UPDATE: Note that the documentation for keyboardHidden says it will ALWAYS return Configuration.KEYBOARDHIDDEN_YES if there is a hard keyboard available on the device(i.e. like a Motorola Droid 1 & 2)
try this or this workaround since its not possible within "simple" sdk method invocation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With