【发布时间】:2023-02-05 03:41:12
【问题描述】:
我只想在 1 个地方显示 FAB - RecyclerviewFragment 并在导航到其他片段时隐藏()它,然后在返回 RecyclerviewFragment 时显示()。例如,在导航到 AddFragment 时隐藏它是可行的,但反之则不行。 FAB 位于 activity_main.xml 中。
【问题讨论】:
标签: android
我只想在 1 个地方显示 FAB - RecyclerviewFragment 并在导航到其他片段时隐藏()它,然后在返回 RecyclerviewFragment 时显示()。例如,在导航到 AddFragment 时隐藏它是可行的,但反之则不行。 FAB 位于 activity_main.xml 中。
【问题讨论】:
标签: android
将以下依赖项添加到您的 gradle。
implementation 'com.google.android.material:material:1.8.0'
并从 activity_main.xml 中删除 fab
并将其添加到您的片段中,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 点击监听器
完毕 :)
【讨论】: