android - 向下滚动时无法隐藏默认操作栏
问题描述
向下滚动回收站视图时如何隐藏默认操作栏?我需要在我的 XML 中创建一个新的操作栏吗?我希望它在用户向下滚动时消失,然后在用户再次向上滚动时重新出现。这在安卓应用程序中很常见。目前我的 XML 看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewObjectives"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabNewObjective"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:background="@color/colorPrimaryLight"
android:clickable="true"
android:focusable="true"
app:srcCompat="@drawable/ic_new_objective"
/>
</RelativeLayout>
解决方案
你必须使用协调器布局来做你想做的事。您还需要在布局中为 appbar 创建一个布局,以便协调器布局可以控制它。这里解释得更好: https ://android-developers.googleblog.com/2015/05/android-design-support-library.html 注意:如果你有一个浮动操作按钮,你也应该使用协调器布局。如果你不这样做,那么它就不能动态响应键盘显示或快餐栏等事件。
推荐阅读
- javascript - 通过下拉菜单在 jstree 的节点中添加数据无法正常工作
- java - 如何在 Java 代码中将文件保存到 S3 时设置请求标头(x-amz-server-side-encryption : aws:kms)?
- spotfire - '>' 后的表达式无效
- mediawiki - 在 Extension:Thanks 中,除了“谢谢”链接之外,是否可以显示收到的评论的“谢谢”数量?
- c# - File.Exists 返回 true,但 File.Move 抛出异常“无法找到指定的文件”。
- python - PyFilesystem 的 s3 文件系统是否支持 python 3?
- node.js - 使用节点 oracledb 导入 sql 脚本并运行它
- reactjs - 如何使用 ra-data-firestore-client 在 react-admin 中实现搜索
- mysql - 连接到本地数据库
- spring - 如何使用资源服务器的授权服务器中的 jdbc 令牌存储访问添加到令牌的自定义声明?