0

I spent hours debugging the same issue described in these SO questions:

Android: How do I prevent the soft keyboard from pushing my view up?

How to avoid soft keyboard pushing up my layout?

Android: How do I prevent the soft keyboard from pushing my view up?

The generally accepted answer is to add android:windowSoftInputMode="adjustPan" to the manifest activity declaration. This works to make the screen stay put when the keyboard is opened, however it does not stop the screen from scrolling when text is entered that has more lines than the screen can display. Here is what I see when I implement that solution:

enter image description here

The header remains when the keyboard opens, however if you type a bunch of lines the header eventually scrolls off the top of the screen.

I tried Googling this problem to try and solve it and none of the solutions worked. Then I managed to solve it by doing the opposite of what the accepted answer above said.

For reference, my layout xml file:

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintTop_toBottomOf="@id/header"
        android:fillViewport="true">

        <EditText
            android:id="@+id/noteText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine"
            android:windowSoftInputMode="adjustPan"/>

    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

My manifest:

    <activity android:name=".activity.MainActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan"
        android:resizeableActivity="true"
        tools:targetApi="n"/>
Joshua W
  • 4,973
  • 5
  • 24
  • 30

1 Answers1

0

I solved this by changing the manifest activity declaration to remove the android:windowSoftInputMode="adjustPan" line from the manifest:

    <activity android:name=".activity.MainActivity"
        android:screenOrientation="portrait"
        android:resizeableActivity="true"
        tools:targetApi="n"/>

...and now everything works as expected, the header stays on the screen when the keyboard was open and text was entered.

Hoping that I can save someone the time it took me to figure this out. Here is what it looks like after fixing the manifest:

enter image description here

Joshua W
  • 4,973
  • 5
  • 24
  • 30