如何防止菜单在 FAB 隐藏上移动?

How to prevent menu from moving on FAB hide?

我有 BottomAppBarFloatingActionButton。当我使用 fab.hide() 时,菜单从右上角移到左上角。如何解决这个问题?

外观:

然后我点击:

您可以像这样删除菜单属性并添加图标:

<com.google.android.material.bottomappbar.BottomAppBar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:fabAlignmentMode="end">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:background="?selectableItemBackgroundBorderless"
        app:srcCompat="@drawable/ic_more" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="?selectableItemBackgroundBorderless"
        app:srcCompat="@drawable/ic_search" />

</com.google.android.material.bottomappbar.BottomAppBar>

删除菜单属性后,如果需要,您必须自己创建溢出菜单。