[ACCEPTED]-How to avoid soft keyboard pushing up my layout?-android-layout

Accepted answer
Score: 160

I did have the same problem and at first 4 I added:


to my manifest file. But this alone 3 did not solve the issue. Then as mentioned 2 by Artem Russakovskii, I added:


in the scrollview.

This 1 is what worked for me.

Score: 72

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

I was able to avoid 3 my bottom row of buttons getting pushed 2 up by the soft keyboard by setting


on the 1 ScrollView that sits above the buttons.

Score: 67

To solve this simply add android:windowSoftInputMode="stateVisible|adjustPan to that activity 1 in android manifest file. for example

Score: 14

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() {
     public void onGlobalLayout() {
        Rect r = new Rect();
        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...

        } else {
           //ok now we know the keyboard is down...


Score: 6

windowSoftInputMode will either pan or resize 8 your activity layout. One thing that you 7 can do is to attach an onFocusChanged listener 6 to your EditText and when the user selects/taps 5 the EditText then you hide or move your 4 navigation buttons out of the screen. When 3 the EditText loses focus then you can put 2 the navigation buttons back at the bottom 1 of the activity.

Score: 0

I had the same problem, but setting windowSoftInputMode did 10 not help, and I did not want to change the 9 upper view to have isScrollContainer="false" because I wanted it 8 to scroll.

My solution was to define the 7 top location of the navigation tools instead 6 of the bottom. I'm using Titanium, so I'm 5 not sure exactly how this would translate 4 to android. Defining the top location of 3 the navigation tools view prevented the 2 soft keyboard from pushing it up, and instead 1 covered the nav controls like I wanted.

More Related questions