我正在尝试使用以下代码获取 android 键盘高度。
popupWindow 解决方案在某些设备上不起作用,是否有其他解决方案?
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;
}
}
});
最佳答案
我会选择 insets
解决方案 - 如果存在,rootWindowInsets.systemWindowInsetBottom
将包括键盘。看看documentation
关于android - 什么都不调整时如何获得键盘高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50343956/