簡體   English   中英

我無法隱藏浮動操作按鈕?

[英]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" />

我的活動

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()此處查看文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM