3

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??

StepUp
  • 36,391
  • 15
  • 88
  • 148
user3548321
  • 523
  • 2
  • 8
  • 18

2 Answers2

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