java - 如何在滚动android studio上隐藏工具栏
问题描述
我试图让我的应用程序上的工具栏在应用程序上向下滚动时消失。我目前的设置似乎无法弄清楚。我想知道我是否可以通过现在如何设置我的工具栏来完成此操作,或者我是否需要重做我的工具栏?
我试图添加,
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>
解决方案
Toolbar 需要是 AppBarLayout 的子级才能在滚动时隐藏。我相信 AppBarLayout 也必须包含在 CoordinatorLayout 中。
不久前对这个问题的回答有一个很好的工作示例:CoordinatorLayout doesn't hide the actionbar
推荐阅读
- java - 使用 FirestorePagingAdapter 或手动分页哪个更好
- excel - VBA - 从关闭的工作簿中的范围复制值
- operating-system - 哪些虚拟磁盘格式与 GPT 兼容?
- java - 如何从 Activity 的片段返回到 viewpager 中的片段
- sql - BigQuery 中的 date_format() 等效项
- sql - 如何使用 Python 和 psycopg2 从 .json 文件在 Postgresql 中创建新表?
- html - 如何在 git 中结帐到子分支
- reactjs - 数组中是否需要使用 NavLink、Interface?
- google-chrome - S3 导入的图像偶尔会损坏:在 Chrome 上呈现,但在 Firefox 上不呈现
- javascript - JavaScript如何创建一个断言来测试一个字符串列表是否包含一些子字符串