如何获得键盘高度调节没事的时候?

问题描述 投票:1回答:2

我试图让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;
                    }

                }
            });
android keyboard height popupwindow adjustpan
2个回答
1
投票

我会去与insets解决方案 - 在rootWindowInsets.systemWindowInsetBottom将如果存在包括键盘。看看documentation


0
投票
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。

© www.soinside.com 2019 - 2024. All rights reserved.