I am trying to hide my FAB in a button click, but it's not working.?
My 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" />
My Activity
show.setOnClickListener {
fabbb.visibility == View.GONE
}
使用方法hide
:
fab.hide();
Your current code is doing nothing, instead of returning true
or false
(most probably true
, as you are using comparison
instead of equal-to
).
You should write code as
show.setOnClickListener {
fabbb.visibility = View.GONE
}
Or even you can use fabbb.hide()
, as another answer suggested if you need animation too.
you need to call a function to hide and show FAB
to hide fab.hide()
to show fab.show()
Check the documentation here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.