我无法隐藏浮动操作按钮?

I can't hide Floating Action Button?

我试图通过单击按钮隐藏我的 FAB,但它不起作用。?

我的XML

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fabbb"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:layout_margin="@dimen/_10sdp"
    android:src="@drawable/ic_arrow_forward_black_24dp"
    android:tint="@color/md_white_1000" />

<Button
    android:id="@+id/show"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/_10sdp"
    android:text="HIDE" />

我的Activity

show.setOnClickListener {
        fabbb.visibility == View.GONE
    }

使用方法hide:

fab.hide();

您当前的代码没有执行任何操作,而不是返回 truefalse(很可能是 true,因为您使用的是 comparison 而不是 equal-to).

你应该把代码写成

show.setOnClickListener {
    fabbb.visibility = View.GONE
}

如果您也需要动画,您甚至可以使用 fabbb.hide(),作为另一个建议的答案。

您需要调用一个函数来隐藏和显示 FAB

隐藏fab.hide() 显示 fab.show() 查看文档 here