Android: Keep TextInputEditText in view when typing

Viewed 345

I'm attempting to create an activity with a couple of TextInputEditText elements. These are placed about half way down the page, causing them to be covered by the keyboard when it appears. As such, I'm trying to use windowSoftInputMode="adjustPan" inside the AppManifest.xml to have the screen scroll to keep the text boxes in view when typing.

However, all attempts at this seem to be failing. Below is the layout hierarchy I'm using, followed up some examples of solutions I've already attempted to no avail.

layout xml

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

    <android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/inputA"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/inputAText"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/inputB"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/inputBText"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

        </android.support.design.widget.TextInputLayout>

   </android.support.constraint.ConstraintLayout>

</ScrollView>

AndroidManifest.xml snippet

<activity
    android:name=".activities.MyActivity"
    android:windowSoftInputMode="adjustPan"
    android:screenOrientation="sensorPortrait"
    android:theme="@style/AppTheme.NoActionBar" />

Attempted Solutions

  1. Add windowSoftInputMode="adjustPan" to the relevant activity in AppManifest.xml (I have also tried adjustResize and adjustPan|adjustNothing as according to other StackOverflow suggestions)
  2. Place the ConstraintLayout inside a ScrollView
  3. Add android:isScrollContainer="false" to said ScrollView
  4. Recreate the layout file with only a ConstraintLayout and TextInputEditText constrained to the bottom of said layout
  5. Change TextInputEditText to EditText and remove TextInputLayout
  6. Changed ConstraintLayout to RelativeLayout

For what should be a fairly simple implementation I'm at a loss. Any further suggestions are appreciated. I'm happy to provide more code samples if necessary.

1 Answers

Found the problem! In my theme I declared <item name="android:windowTranslucentStatus">true</item>. For some reason, this breaks windowSoftInputMode="adjustPan", and as such I removed it.

In order to keep the status bar transparent, I use <item name="android:statusBarColor">@color/transparent</item>.

Hopefully someone, someday finds this useful.

Related