[英]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):
如果我单击 TextInputLayout,键盘会打开,但我的工具栏将扩展,如下所示(如果键盘关闭,则工具栏具有通常的大小):
My xml-files:我的 xml 文件:
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>
Try removing the android:fitsSystemWindows="true"
from your toolbar尝试从工具栏中删除
android:fitsSystemWindows="true"
Edit: Maybe you should use a coordinatorlayout instead and put your toolbar in there.编辑:也许您应该改用 coordinatorlayout 并将您的工具栏放在那里。
I had the same problem and eventually got around it by using CoordinatorLayout as my activity root with app:statusBarColor="@color/some_color"
and moving android:fitsSystemWindows="true"
there.我遇到了同样的问题,最终通过使用 CoordinatorLayout 作为我的活动根并使用
app:statusBarColor="@color/some_color"
并将android:fitsSystemWindows="true"
移动到那里来解决它。 Probably not the best solution but the only one that worked with my layout.可能不是最好的解决方案,但唯一适用于我的布局的解决方案。
<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>
I eventually managed to solve my problem by putting the ScrollView
directly into the ConstraintLayout
like this (and not using a RelativeLayout
):我最终设法通过像这样将
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.