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

后端 未结 28 1192
南笙
南笙 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 06:01

    Try to use this:

    android:windowSoftInputMode="stateHidden|adjustPan"
    
    0 讨论(0)
  • 2020-11-22 06:01

    There are two ways of solving this problem. Go to the AndroidManifist.xml, and in the name of your activity, add this line

       android:windowSoftInputMode="adjustPan"
    

    As in the below code, I have added to the Register Activity.

     <activity android:name=".Register"
                android:windowSoftInputMode="adjustPan">
    

    In the second way, go to your activity, and in your onCreate method, add this code.

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    
    0 讨论(0)
  • 2020-11-22 06:03

    Just a single line to be added...

    Add android:windowSoftInputMode="stateHidden|adjustPan" in required activity of your manifest file.

    I just got solved :) :)

    0 讨论(0)
  • 2020-11-22 06:04

    For future readers.

    I wanted specific control over this issue, so this is what I did:

    From a fragment or activity, hide your other views (that aren't needed while the keyboard is up), then restore them to solve this problem:

                rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        Rect r = new Rect();
                        rootView.getWindowVisibleDisplayFrame(r);
                        int heightDiff = rootView.getRootView().getHeight() - (r.bottom - r.top);
    
                        if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                        //ok now we know the keyboard is up...
                            view_one.setVisibility(View.GONE);
                            view_two.setVisibility(View.GONE);
    
                        }else{
                        //ok now we know the keyboard is down...
                            view_one.setVisibility(View.VISIBLE);
                            view_two.setVisibility(View.VISIBLE);
    
                        }
                    }
                });
    
    0 讨论(0)
  • 2020-11-22 06:05

    This one worked for me

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
    
    0 讨论(0)
  • 2020-11-22 06:07

    Well i have watched these answers but in my case i fell into the same issue and got refuge through a very handy and easiest solution that involves putting a very small innocent attribute in your Scrollview tag residing in your xml file. That is

    android:isScrollContainer="false"
    

    Good luck!

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