【问题标题】:Showing FAB in particular fragment在特定片段中显示 FAB
【发布时间】:2023-02-05 03:41:12
【问题描述】:

我只想在 1 个地方显示 FAB - RecyclerviewFragment 并在导航到其他片段时隐藏()它,然后在返回 RecyclerviewFragment 时显示()。例如,在导航到 AddFragment 时隐藏它是可行的,但反之则不行。 FAB 位于 activity_main.xml 中。

【问题讨论】:

    标签: android


    【解决方案1】:

    将以下依赖项添加到您的 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 点击监听器

    完毕 :)

    【讨论】:

    • 我实际上要添加滚动 FAB 行为,所以它对我不起作用,因为整个布局将以这种方式运行。
    猜你喜欢
    • 2017-03-02
    • 2022-01-10
    • 1970-01-01
    • 2019-10-23
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    相关资源
    最近更新 更多