Search code examples
androidtoolbar

Toolbar extends when keyboard opens


I have a toolbar that is beneath the status bar. If I click on a TextInputLayout, the keyboard opens but my toolbar will extend as shown here (if the keyboard is closed, the Toolbar has the usual size):

my problem

My xml-files:

The toolbar:

<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/backgroundColor"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.SubAppBarOverlay"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    app:title="Title"
    android:elevation="4dp" />

Where it is included:

<androidx.constraintlayout.widget.ConstraintLayout 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="?attr/backgroundColor"
    android:fitsSystemWindows="false"
    tools:context=".EditDayActivity">

    <include
        android:id="@+id/sub_toolbar"
        layout="@layout/sub_toolbar"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <RelativeLayout
        android:id="@+id/scrollViewContainer"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/sub_toolbar"
        android:fitsSystemWindows="false">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:fitsSystemWindows="true">

   </ScrollView>
    </RelativeLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Solution

  • I eventually managed to solve my problem by putting the ScrollView directly into the ConstraintLayout like this (and not using a RelativeLayout):

    <androidx.constraintlayout.widget.ConstraintLayout
        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="?attr/backgroundColor"
        android:fitsSystemWindows="true"
        tools:context=".MyActivity">
    
        <include
            ... />
    
        <ScrollView 
            ... />
    </androidx.constraintlayout.widget.ConstraintLayout>