首页 > 解决方案 > BottomAppBar 和 FloatingActionButton 应用程序:layout_scrollFlags 行为

问题描述

我目前在我的布局中使用 BottomAppBar 和 FloatingActionButton 的组合(显然在 CoordinatorLayout 内部):请参阅布局:

  <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:backgroundTint="@color/primarycolor"
        app:theme="@style/ThemeOverlay.MaterialComponents.Dark"
        app:fabAlignmentMode="center"
        app:layout_scrollFlags="scroll|enterAlways"
        app:navigationIcon="@drawable/ic_menu_time" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|enterAlways"
        app:backgroundTint="#FFFF0000"
        app:layout_anchor="@id/bar"
        app:rippleColor="#FFFF8888"
        app:srcCompat="@drawable/ic_fab_search" />

列表滚动的行为就像 BottomAppBar 的魅力,但我对 FloatingActionButton 有很大的问题。

正如您在下面的屏幕截图中看到的那样,BottomAppBar 完全消失了,这很棒,但对于 FAB,我无法得到相同的结果。它只是在底部移动了一点。

知道我可以从哪里开始解决这个问题吗?正确的行为是 FAB 跟随 Bar 并简单地消失

在此处输入图像描述

在卷轴之后:

在此处输入图像描述

标签: androidfloating-action-buttoncoordinator-layoutandroid-bottomappbar

解决方案


您应该自己隐藏 FAB。只需调用fab.hide()fab.show()管理其可见性。


推荐阅读