Is there any way to hide/disable Floating action button in Android via xml file without editing Java file? Just want to hide a share button in an app and I tried editing related xml file. Tried to set invisible, gone etc but none of these works. Button is still there. At least to reduce the size of button to almost invisible? I think we cant change fab:fab_size="normal"
to other values. So that too didn't work. So is there any way??
Asked
Active
Viewed 2,756 times
3

StepUp
- 36,391
- 15
- 88
- 148

user3548321
- 523
- 2
- 8
- 18
-
1Did you try visibility=gone ? – Rakshit Nawani Apr 11 '16 at 06:07
-
Can you show your XML where you used invisible attribute. – Shree Krishna Apr 11 '16 at 06:08
-
1Similar question already answered here. http://stackoverflow.com/questions/31269958/floatingactionbutton-doesnt-hide – MrWaqasAhmed Apr 11 '16 at 06:09
-
yes. already tried visibility=gone, visibility=invisible but it's not working – user3548321 Apr 11 '16 at 06:11
-
Show your XML code – Rakshit Nawani Apr 11 '16 at 06:13
-
So this means, we can't hide it via xml only if app:layout_anchor attribute is there. Right? no other way to hide via xml? – user3548321 Apr 11 '16 at 06:13
-
what if you remove `app:layout_anchor` attribute ? – Shree Krishna Apr 11 '16 at 06:16
-
– user3548321 Apr 11 '16 at 06:17
-
No. deleting will not work. I tried but another activity important activity will not work if i delete it. – user3548321 Apr 11 '16 at 06:18
-
@shree krishana: I didn't tried that yet. i was asking, is there an way to do this without touching java. only via xml – user3548321 Apr 11 '16 at 06:20
-
Thanks everybody. i was aware of the app:layout_anchor issue before i posted the question, but my question was about hiding it via xml without touching java code. I think it's not possible. Anyway I'm keeping this question open. Let's see if anybody have some tricks to do this via xml only. Thanks a lot for replies. – user3548321 Apr 12 '16 at 01:17
2 Answers
5
Discussed already on this issue, Main reason is
If you set a set a
FloatingActionButton
to be anchored, you lose control of the visibility.
So you have to remove layout_anchor
attribute from FloatingActionButton
first.
You have to use java somewhere at the point. Cant do it with only with XML
The trick given is
To wrap your FAB in a coordinator layout that is not the root of your entire layout, but as a sort of overlay to everything. From there you can manage the visibility of the coordinator layout initially so it's invisible, then make it visible when you call
fab.show()
.

Shree Krishna
- 8,474
- 6
- 40
- 68
-1
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
fab:menu_animationDelayPerItem="50"
fab:menu_backgroundColor="@android:color/transparent"
fab:menu_colorNormal="@color/lightgrey"
fab:menu_colorPressed="@color/transparant"
fab:menu_colorRipple="#99FFFFFF"
fab:menu_fab_hide_animation="@anim/my_hide_animation"
fab:menu_fab_label=""
fab:menu_fab_show_animation="@anim/my_show_animation"
fab:menu_fab_size="normal"
fab:menu_icon="@drawable/plus"
fab:menu_openDirection="up"
fab:menu_showShadow="false"
android:visibility="gone">

Jinal Patel
- 699
- 5
- 15