我的MainActivity布局带有带有TabLayout和ViewPager的AppBarLayout。我无法在添加到“查看寻呼机”的滚动“片段”布局上隐藏工具栏。但是我可以隐藏在AppBarLayout上滚动的工具栏。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:windowBackground">
<com.google.android.material.appbar.AppBarLayout
android:background="?android:windowBackground"
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/toolbar" />
<com.google.android.material.tabs.TabLayout
android:background="?android:windowBackground"
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="?colorAccent"
app:tabIndicatorFullWidth="false"
app:tabIndicatorHeight="3dp"
app:tabMode="scrollable"
app:tabBackground="?android:windowBackground"
app:tabSelectedTextColor="?colorAccent"
app:tabTextAppearance="@style/TabTextAppearance.Timber" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
您需要将此行添加到AppBarLayout
:app:layout_scrollFlags="scroll|exitUntilCollapsed"