[ACCEPTED]-How to avoid soft keyboard pushing up my layout?-android-layout
I did have the same problem and at first 4 I added:
<activity
android:name="com.companyname.applicationname"
android:windowSoftInputMode="adjustPan">
to my manifest file. But this alone 3 did not solve the issue. Then as mentioned 2 by Artem Russakovskii, I added:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="false">
</ScrollView>
in the scrollview.
This 1 is what worked for me.
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
android:isScrollContainer="false"
on the 1 ScrollView
that sits above the buttons.
To solve this simply add android:windowSoftInputMode="stateVisible|adjustPan
to that activity 1 in android manifest file. for example
<activity
android:name="com.comapny.applicationname.activityname"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustPan"/>
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
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.
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
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.