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

后端 未结 28 1306
南笙
南笙 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:49

    I have solved my issue by adding

     android:windowSoftInputMode="adjustNothing" 
    

    In manifest file add.

    and making the Recyclerviews constraint isScrollContainer to false .

    android:isScrollContainer="false"
    
    0 讨论(0)
  • 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) {
    
                }
            }
        });
    
    }
    
    0 讨论(0)
  • 2020-11-22 05:56

    These answers here didn't help me. So I tried this:

    android:windowSoftInputMode="adjustResize"
    

    This worked like a charm, Now the header of my app doesn't disappear. Its smoother.

    0 讨论(0)
  • 2020-11-22 05:58

    In my case, the reason the buttons got pushed up was because the view above them was a ScrollView, and it got collapsed with the buttons pushed up above the keyboard no matter what value of android:windowSoftInputMode I was setting.

    I was able to avoid my bottom row of buttons getting pushed up by the soft keyboard by setting android:isScrollContainer="false" on the ScrollView that sits above the buttons.

    0 讨论(0)
  • 2020-11-22 05:58

    You can try to add this attribute dynamically, by putting the following code in the onCreate method of your activity:

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    

    This worked for me, but that:

    android:windowSoftInputMode="adjustPan"
    

    didnt.

    0 讨论(0)
  • 2020-11-22 05:58

    I was struggling for a while with this problem. Some of the solutions worked however some of my views where still being pushed up while others weren't... So it didn't completely solve my problem. In the end, what did the job was adding the following line of code to my manifest in the activity tag...

    android:windowSoftInputMode="stateHidden|adjustPan|adjustResize"
    

    Good luck

    0 讨论(0)
提交回复
热议问题