我试图让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
final Window mRootWindow = getWindow();
ll_main.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
public void onGlobalLayout(){
int screenHeight = ll_main.getRootView().getHeight();
Rect r = new Rect();
View view = mRootWindow.getDecorView();
view.getWindowVisibleDisplayFrame(r);
int keyBoardHeight = screenHeight - r.bottom;
}
});
在这个link全部代码。这个环节也帮助AdjustNothing。