我想在只有一个地方显示FAB - RecyclerviewFragment,并在导航到其他片段时隐藏()它,然后显示()每当回到RecyclerviewFragment。例如,当导航到AddFragment时隐藏它是有效的,但另一种方式则不是。FAB位于activity_main.xml中。
将下列依赖项添加到gradle中。
implementation 'com.google.android.material:material:1.8.0'
并从activity_main.xml中删除fab
并将它添加到你的fragment中,其中recyclerview是
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="32dp"
android:src="@drawable/ic_add_alarm_black_24dp"
android:background="@color/colorAccent"
app:backgroundTint="@color/colorAccent"
app:fabSize="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
和调用Fab在片段
中单击监听器:完成)