Created
July 28, 2016 10:00
-
-
Save vishalpatel1327/9080771e00ba52f292a67746aff678ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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