Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android soft keyboard spoils layout when appears

Here is a layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1" />

        <FrameLayout
            android:background="#0000ff"
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1" />

    </LinearLayout>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

enter image description here

I want blue bar to remain intact when EditText is touched and soft keyboard appears. I.e. I want its size and position to be preserved. I tried all four possible values for my activity's parameter android:windowSoftInputMode in the AndroidManifest. And always my blue bar moves or shrinks on soft keyboard appearing:

android:windowSoftInputMode="adjustUnspecified" or by default:

enter image description here

android:windowSoftInputMode="adjustPan" or android:windowSoftInputMode="adjustNothing":

enter image description here

android:windowSoftInputMode="adjustResize":

enter image description here

Is it ever possible to keep it the same size and position when soft keyb appears?

like image 891
Nick Avatar asked Oct 30 '12 10:10

Nick


People also ask

How do I get rid of soft keyboard on Android?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow , passing in the token of the window containing your focused view. This will force the keyboard to be hidden in all situations. In some cases, you will want to pass in InputMethodManager.

What is soft keyboard in Android?

The soft keyboard (also called the onscreen keyboard) is the main input method on Android devices, and almost every Android developer needs to work with this component at some point.


Video Answer


2 Answers

you must use <ScrollView> as main layout. example:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
   ....
</ScrollView>

or use this code in AndroidManiFest.xml:

<activity
     android:windowSoftInputMode="adjustNothing">
</activity>
like image 63
سعید .م Avatar answered Nov 13 '22 04:11

سعید .م


Since the input is coming into an EditText of yours, it's always going to move something.

Consider having two layouts, one for when the keyboard is down, one for when the keyboard is up.

Using a ViewSwitcher may help with that.

like image 42
Richard Taylor Avatar answered Nov 13 '22 06:11

Richard Taylor