【发布时间】:2015-05-06 12:28:20
【问题描述】:
我正在尝试使用以下代码获取 android 键盘高度
parentLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
parentLayout.getWindowVisibleDisplayFrame(r);
int screenHeight = parentLayout.getRootView().getHeight();
int heightDifference = screenHeight - (r.bottom);
previousHeightDiffrence = heightDifference;
if (heightDifference > 100) {
isKeyBoardVisible = true;
changeKeyboardHeight(heightDifference);
} else {
if(emojiKeyboard.getVisibility()==View.INVISIBLE){
emojiKeyboard.setVisibility(View.GONE);
}
isKeyBoardVisible = false;
}
}
});
这适用于android:windowSoftInputMode="adjustPan",但这会导致我的活动屏幕在默认键盘出现时向上移动。
我需要的只是获取键盘高度并在默认键盘下显示我的自定义键盘,据我说只有android:windowSoftInputMode="adjustPan" 或android:windowSoftInputMode="AdjustNothing" 才有可能。
如果设置android:windowSoftInputMode="adjustNothing" 那么我无法获得键盘高度。
我需要替代解决方案来解决我的问题。
提前谢谢!
【问题讨论】:
标签: android android-layout keyboard android-input-method