Android: How do I prevent the soft keyboard from pushing my view up?

后端 未结 28 1683
南笙
南笙 2020-11-22 05:10

I have a vertical sliding drawer at the bottom of my app. When the soft keyboard opens, it pushes the tab for the drawer up, so it sits atop the keyboard. I actually want it

28条回答
  •  庸人自扰
    2020-11-22 05:54

    None of them worked for me, try this one

     private void scrollingWhileKeyboard() {
        drawerlayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
    
                Rect r = new Rect();
                try {
                    drawerlayout.getWindowVisibleDisplayFrame(r);
                    int screenHeight = drawerlayout.getRootView().getHeight();
                    int keypadHeight = screenHeight - r.bottom;
                    if (keypadHeight > screenHeight * 0.15) {
                        tabLayout.setVisibility(View.GONE);
                    } else {
                        tabLayout.setVisibility(View.VISIBLE);
                    }
                } catch (NullPointerException e) {
    
                }
            }
        });
    
    }
    

提交回复
热议问题