Android 向下滚动时无法隐藏默认操作栏
在向下滚动我的recyclerview时,如何隐藏默认的操作栏? 我是否需要在XML中创建新的操作栏?我希望它在用户向下滚动时消失,然后在用户再次向上滚动时重新出现。这在android应用程序中很常见。 当前我的XML如下所示:Android 向下滚动时无法隐藏默认操作栏,android,kotlin,Android,Kotlin,在向下滚动我的recyclerview时,如何隐藏默认的操作栏? 我是否需要在XML中创建新的操作栏?我希望它在用户向下滚动时消失,然后在用户再次向上滚动时重新出现。这在android应用程序中很常见。 当前我的XML如下所示: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="h
<?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创建布局,以便协调器布局可以控制它。 这里有更好的解释:
注意:如果您有一个浮动操作按钮,那么您也应该使用协调器布局。如果您不这样做,则它无法动态响应诸如键盘显示或快捷键之类的事件。工具栏在哪里?我在问题中说过。它在AppTheme中,我需要自己创建一个吗?它在AppTheme中是什么意思?你使用的是工具栏还是动作栏?ActionBar*ups,我的宝贝在这里看不到任何工具栏/动作栏,所以每次使用FAB时,使用CoordinatorLayout是一种很好的做法?这不是绝对必要的,但如果没有它,它将无法制作一些动画。