[英]Toolbar extends when keyboard opens
我有一个位于状态栏下方的工具栏。 如果我单击 TextInputLayout,键盘会打开,但我的工具栏将扩展,如下所示(如果键盘关闭,则工具栏具有通常的大小):
我的 xml 文件:
工具栏:
<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" />
包括在哪里:
<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>
尝试从工具栏中删除android:fitsSystemWindows="true"
编辑:也许您应该改用 coordinatorlayout 并将您的工具栏放在那里。
我遇到了同样的问题,最终通过使用 CoordinatorLayout 作为我的活动根并使用app:statusBarColor="@color/some_color"
并将android:fitsSystemWindows="true"
移动到那里来解决它。 可能不是最好的解决方案,但唯一适用于我的布局的解决方案。
<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"
android:fitsSystemWindows="true"
tools:context=".MyActivity"
app:statusBarBackground="@color/some_color">
...
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我最终设法通过像这样将ScrollView
直接放入ConstraintLayout
来解决我的问题(而不是使用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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.