Skip to content

Instantly share code, notes, and snippets.

@vishalpatel1327
Created July 28, 2016 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishalpatel1327/9080771e00ba52f292a67746aff678ff to your computer and use it in GitHub Desktop.
Save vishalpatel1327/9080771e00ba52f292a67746aff678ff to your computer and use it in GitHub Desktop.
final View activityRootView = activity.getWindow().getDecorView().findViewById(android.R.id.content);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
int contentViewTop = activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(activity);
if (heightDiff > 200) { // 99% of the time the height diff will be due to a keyboard.
if (isOpened == false) {
// your stuff when keyboard down
}
isOpened = true;
} else if (isOpened == true) {
// keyboard Up....
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment