Fab 没有被底部导航上方的小吃店推上去

Fab not being pushed up by snackbar above bottom Navigation

(这个错误出现在一个大项目中,所以我做了一个小的以便于演示)

我已经为这个问题苦苦挣扎了一段时间,但我在任何地方都找不到答案

~布局

我想在显示 Snackbar 时上推 fab。当底部导航栏被移除并且我显示一个小吃栏时,晶圆厂被推上去。但是当我插入底部导航栏时,出现了snackbar,但是fab并没有被推上去

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        app:layout_anchor="@id/bar"
        app:layout_anchorGravity="bottom|end" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:background="@color/design_default_color_secondary"
        android:id="@+id/bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_insetEdge="bottom"
        android:layout_gravity="bottom"
        app:menu="@menu/menu"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val button = findViewById<Button>(R.id.button)
        button.setOnClickListener {
            Snackbar
                .make(it, "tttt", Snackbar.LENGTH_LONG)
                .setAnchorView(findViewById(R.id.bar))
                .show()
        }
    }
}

提前致谢:)

将底部导航移动到另一个布局并将 CoordinatorLayout 包裹在线性布局中,现在小吃店应该以 CoordinatorLayout 为根并且 CoordinatorLayout 将在底部有工厂,所以当小吃来的时候它会抬起它。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/snackRoot"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab_add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="16dp"
            android:src="@drawable/ic_android_circle" />
    </androidx.coordinatorlayout.widget.CoordinatorLayout>


    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/design_default_color_secondary"
        app:layout_insetEdge="bottom"
        app:menu="@menu/menu" />

</LinearLayout>

显示小吃店

Snackbar
.make(activity.findViewById(R.id.snackRoot),
"tttt", 
Snackbar.LENGTH_LONG)
.show()