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) {
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).
source share