android - Android:使用 jetpack 导航,如何在不破坏后退按钮的情况下向片段添加折叠工具栏布局?
问题描述
我在下面有这个 collapsingtoolbar 代码,它工作得很好。但是,当我切换到使用 Jetpack Navigation(导航图)时,点击应用程序上的后退按钮会导致所有其他视图突然像这样向下移动。我怎样才能避免这种情况发生?
代码:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/diningAppBar"
android:layout_width="match_parent"
android:layout_height="356dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/diningToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="false"
>
<edu.msu.msumobile.ui.shared.CustomImageView
android:id="@+id/diningImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.3"
android:background="@android:color/black"
android:fitsSystemWindows="true"/>
<TextView
android:id="@+id/diningHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="?attr/actionBarSize"
android:textColor="@android:color/white"
android:textSize="48dp"
android:paddingStart="@dimen/text_margin"
android:paddingEnd="@dimen/text_margin"
android:fitsSystemWindows="true"
android:layout_gravity="bottom|end"
android:gravity="bottom|end"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.5"
/>
<androidx.appcompat.widget.Toolbar
android:id="@+id/diningDetailToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/diningDetailTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:tabIndicatorColor="@color/textLightColor"
app:tabSelectedTextColor="@color/textSelectedColor"
app:tabTextColor="@color/textLightColor"
/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/diningViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
解决方案
解决了。原来,添加
android:fitsSystemWindows="true"
打破喷气背包导航。从上面的代码中删除那些删除了每个其他片段顶部多余的白条。
推荐阅读
- c - %lo(source)($6) 和 .frame 在汇编代码中是什么意思?
- kotlin - 带有kotlin的黄瓜参数类型
- graphql - 如何使我的 hasura 动作准备好用于我的 ci / cd 测试?
- c - 如何知道 Linux 中看门狗重启的原因?
- python - 为什么当我输入一个值时程序会退出?
- vue.js - 当我使用 Axios 获取数据时,我的 JS 代码不起作用
- python - 有没有办法可以在 python 中使用多线程或多处理来连接到 200 个不同的服务器并从它们下载数据
- java - 带有图像的 HTML 和 css 在 iText7 中重叠 html 到 java 中的 pdf 转换
- javascript - (Angular8)为什么点击事件去路由'/#'?
- c# - 如何通过蓝牙扫描另一台设备-Xamarin