I want to create an application with login / layout activity similar to what the Facebook application has. I mean, when the text field is focused on a soft keyboard, I pushed the whole view, but did not crush the logo. I tried android:windowSoftInputMode="adjustPan/adjustResize" , but that is not what I was trying to achieve.
I found this question about SO, maybe it will make everything clearer, but it has no solution to the problem.
I also tried various types of layouts, but the soft keyboard only pushes the focused <EditText> up. Please guide me.
UPDATE:




<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="#DDDDDD"> <RelativeLayout android:height="0dp" android:layout_weight="1" android:layout_height="0dp" android:layout_width="fill_parent" android:background="#ff0000"> <ImageView android:layout_centerVertical="true" android:layout_height="fill_parent" android:layout_width="fill_parent"></ImageView> </RelativeLayout> <RelativeLayout android:height="0dp" android:layout_height="0dp" android:layout_weight="1" android:layout_width="fill_parent" android:background="#00ff00"> </RelativeLayout> <RelativeLayout android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#0000ff" android:height="0dp" > <Button android:layout_width="fill_parent" android:layout_height="40dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:text="Log in" /> <EditText android:layout_width="fill_parent" android:layout_height="40dp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:padding="4dp" android:hint="password" android:inputType="textPassword" > </EditText> <EditText android:id="@+id/editText1" android:hint="login" android:padding="4dp" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" ></EditText> </RelativeLayout> </LinearLayout>
Working UPDATE solution I canβt insert the whole XML file here, but the structure should be enough. Based on the answer of Gabe Sechan.
Layout{ Layout top weight 1 Layout mid weight 1 Layout bot weight 1 }
Layouts for children are set to:
android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"
And here is the Java code for activity (keyboard up / down):
View top, mid, bot; final View activityRootView = findViewById(R.id.loginLayout); activityRootView.getViewTreeObserver().addOnGlobalLayoutListener( new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int heightDiff = activityRootView.getRootView() .getHeight() - activityRootView.getHeight(); if (heightDiff > 100) {
On the keyboard, you need to change the weight transfer to the keyboard and to the keyboard down to return to the default (layout that you installed via xml / java). I checked the code on 2.3.x and above. And don't forget to use android:inputType="textFilter" for the EditText login and password to remove input suggestions and save some pixels. In your manifest for android:windowSoftInputMode="adjustResize|stateHidden" activity android:windowSoftInputMode="adjustResize|stateHidden" . stateHidden used so that the keyboard will not work when activity is loading. Hope it helps. Good luck.