我试图让应用程序上的工具栏在应用程序上向下滚动时消失。我似乎无法用我当前的设置弄清楚这一点。我想知道是否可以通过现在设置工具栏的方式来完成此操作,或者我是否需要重做我的工具栏?
我尝试添加,
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
因为有人告诉我把它放进去,但它似乎不起作用。
我的工具栏:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/global_color_primary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
最佳答案
工具栏需要是 AppBarLayout 的子级,才能在滚动时隐藏。我相信 AppBarLayout 也必须包含在 CoordinatorLayout 中。
不久前这个问题的答案有一个很好的工作示例:CoordinatorLayout doesn't hide the actionbar
关于java - 如何让工具栏在滚动时隐藏 android studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57422264/