Problem selecting text in TextInputEditText within NestedScrollView

Viewed 92

I have a TextInputEditText inside a NestedScrollView, together with some other views. If the TextInputEditText contains lots of text and the user tries to select some text, starting from the middle all the way up to the top, the blue top cursor cannot be moved up. Instead, it hides behind the toolbar and cannot be moved any further, even though there is still lots of text toward the top. See here:

enter image description here

This is my resource xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".OfferingInputActivity">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/OfferingsMaterialTheme.AppBarOverlay">

    <include layout="@layout/toolbar"/>

</com.google.android.material.appbar.AppBarLayout>

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".OfferingInputActivity"
    android:fillViewport="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/material_white_1000"
        android:orientation="vertical">
        <include
            android:id="@+id/offering_details_header"
            layout="@layout/offering_details_header"
            android:layout_marginTop="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
        <include
            layout="@layout/favorite_offered_checkboxes"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/date_card_spacing"
            android:layout_marginEnd="@dimen/date_card_spacing" />

        <RadioGroup
            android:id="@+id/peace_type_ratio_group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/date_card_spacing"
            android:layout_marginEnd="@dimen/date_card_spacing"
            android:visibility="visible"
            android:orientation="horizontal">
            <RadioButton android:id="@+id/radio_thanksgiving"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:checked="true"
                android:layout_weight="1"
                android:text="@string/thanksgiving" />
            <RadioButton android:id="@+id/radio_vow"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/vow" />
            <RadioButton android:id="@+id/radio_freewill"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/freewill" />
        </RadioGroup>

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/date_card_spacing"
            android:layout_marginRight="@dimen/date_card_spacing"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:hint="@string/verses">
            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/edittext_verses"
                android:inputType="textMultiLine"
                android:gravity="top|start"
                android:minLines="5"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginLeft="@dimen/date_card_spacing"
            android:layout_marginRight="@dimen/date_card_spacing"
            android:hint="@string/experience">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/edittext_experience"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:minLines="10"
                android:gravity="top|start"
                android:inputType="textMultiLine" />
        </com.google.android.material.textfield.TextInputLayout>

        <include layout="@layout/wave_heave_input"
            android:id="@+id/peace_type_wave_heave_layout"
            android:visibility="visible"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

And in my manifest, I have this:

    <activity
        android:name=".OfferingInputActivity"
        android:parentActivityName=".MainActivity"
        android:windowSoftInputMode="stateVisible|adjustResize"/>

Any ideas how I can achieve a proper behavior for the user to be able to select text from the middle section all the way up to the top?

1 Answers

Apparently, this is a bug in TextInputEditText, as reported here.

Related