4

I have a layout which has a toolbar at the top and several EditText views:

<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">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
    </android.support.v7.widget.Toolbar>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/my_toolbar">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/edit_text1"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/edit_text2"/>

            ...

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/edit_text7"/>
    </LinearLayout>

</RelativeLayout>

While some EditText which are closer to the bottom of the screen opens the soft Keyboard, the whole screen(contains the toolbar) will be pushed up. Is there any way to make soft keyboard push up the whole screen except the toolbar (Fix the toolbar)?

Some existing answers can actually fix the whole screen, but EditText which are closer to the bottom might also be blocked by the soft keyboard.

Can anyone give me a good solution?

Community
  • 1
  • 1
Rayliu521
  • 323
  • 1
  • 3
  • 8

2 Answers2

4

Use a ScrollView.

<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">

<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">
</android.support.v7.widget.Toolbar>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/my_toolbar">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/edit_text1"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/edit_text2"/>

            ...

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/edit_text7"/>
    </LinearLayout>

</ScrollView>

Oliver Kranz
  • 3,741
  • 2
  • 26
  • 31
4

Put android:fitsSystemWindows="true" in first relative layout

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

and in manifest add this

android:windowSoftInputMode="adjustPan"
Deepak
  • 756
  • 4
  • 10
  • Thanks for your post, I tried but it didn't work as my expectation right now. Maybe you lead me on the right track, I'll keep on trying. – Rayliu521 Dec 21 '15 at 02:06
  • worked for me , thanks! Do you know if I can make ths adjuctPan behavior to a specific layout or view? instead of defining it to the whole app in the manifest. Cause there are places where I would rather use adjustResize – BVtp Aug 08 '16 at 06:34
  • you can define adjustPan for each activity, you need not to define it for whole application. – Deepak Aug 23 '16 at 11:54
  • 1
    This did not work for me. `adjustResize` did though – Vucko Apr 18 '19 at 08:35