Search code examples
androidlayoutkeyboard

How to push button when keyboard is opened


I have RelativeLayout -> ScrollView -> ConstraintLayout -> EditText..Button -> /Constraint -> /ScrollView -> /RelativeLayout When keyboard is opened it pushes only EditText, but Button is hidden beneath keayboard.

What I tried: android:windowSoftInputMode="adjustResize" / adjustPan /Nothig / StateHidden.... fistSystemWindow = true fillViewPort = true alignParentBottom after change Constraint to Relative layout NestedScrollView instead of ScrollView

Nothing works. I test on Android 6.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    tools:context=".screens.news.leave.NewsDetailActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <androidx.core.widget.NestedScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:paddingTop="@dimen/margin_large">

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

........
           <EditText
                android:id="@+id/commentET"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@id/sendComment"
                android:layout_marginStart="@dimen/margin_medium"
                android:layout_marginTop="@dimen/margin_medium"
                android:layout_marginEnd="@dimen/margin_medium"
                android:fontFamily="@font/roboto_regular"
                android:hint="Оставить комментарий"
                android:textColor="#878787"
                android:textSize="@dimen/textsize_large"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/commentsRV" />

            <Button
                android:id="@+id/sendComment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_medium"
                android:layout_marginEnd="@dimen/margin_medium"
                android:layout_marginBottom="16dp"
                android:background="@drawable/button_selector"
                android:text="Оставить комментарий"
                android:textColor="@color/textWhite"
                android:visibility="visible"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/commentET" />
...
   </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.core.widget.NestedScrollView>
</RelativeLayout>

How to push button over keyboard? PS. Drop off relative layout is impossible, since it has some views inside, that can not be scrollable


Solution

  • I find kind of workaround. In onResume I add listener to parentView changed size listener. Inside it I scroll down to bottm when parentView size is changed

    newsLeaveParentView.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
                if (bottom < oldBottom){
                    scrollView.fullScroll(ScrollView.FOCUS_DOWN);
                }
            }