我试图通过以下代码获得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;
}
}
});
答案 0 :(得分:1)
我将采用insets
解决方案-其中rootWindowInsets.systemWindowInsetBottom
将包括键盘(如果存在)。看看documentation
答案 1 :(得分:0)
now()
此link的完整代码。此链接也有助于AdjustNothing。