Created
April 11, 2014 13:18
-
-
Save tuoxie007/10468136 to your computer and use it in GitHub Desktop.
监听键盘显示和隐藏事件
This file contains 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 = getWindow().getDecorView().findViewById(R.id.post_editor_dialog); | |
if (activityRootView != null) { | |
ViewTreeObserver observer = activityRootView.getViewTreeObserver(); | |
if (observer != null) { | |
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | |
int lastHeightDiff; | |
@Override | |
public void onGlobalLayout() { | |
View rootView = activityRootView.getRootView(); | |
if (rootView != null) { | |
int heightDiff = rootView.getHeight() - activityRootView.getHeight(); | |
if (heightDiff != lastHeightDiff) { | |
if (heightDiff > 200) { | |
// onKeyboardShow(); | |
} else { | |
// onKeyboardHide(); | |
} | |
lastHeightDiff = heightDiff; | |
} | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment