什么都不调整时如何获得键盘高度?

时间:2018-05-15 06:52:20

标签: android keyboard height popupwindow adjustpan

我试图通过以下代码获得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;
                    }

                }
            });

2 个答案:

答案 0 :(得分:1)

我将采用insets解决方案-其中rootWindowInsets.systemWindowInsetBottom将包括键盘(如果存在)。看看documentation

答案 1 :(得分:0)

now()

link的完整代码。此链接也有助于AdjustNothing。