How to create a submenu for Floating Action Button in Android Material Design?

12,682

It is not possible directly. android.support.design.widget.FloatingActionButton is a subclass of ImageView and it can't host children. You have to implement your own ViewGroup (a Vertical LinearLayout should be enough) and put the FloatingActionButton into it

Share:
12,682
lopez.mikhael
Author by

lopez.mikhael

I'm an french engineer in computer science development and specialized in mobile technologies in particular Android. Find my applications on my Website Or find my projects in GitHub

Updated on June 21, 2022

Comments

  • lopez.mikhael
    lopez.mikhael almost 2 years

    I want to create a submenu after click in my floating action button like this :

    SubMenu Fab

    I already know this Library :

    https://github.com/futuresimple/android-floating-action-button

    But I want to create this with the native FAB of android support design :

    compile 'com.android.support:design:23.+'
    

    and

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:src="@drawable/ic_add" />
    
  • lopez.mikhael
    lopez.mikhael over 8 years
    Thanks. Do you know a library with the implemation of that ? The other view in your ViewGroup is also a FAB ? Because I think, I show in android developer webside that it's not a good practice to add multiple FAB in your view.
  • Blackbelt
    Blackbelt over 8 years
    on github you can find couple of them. Here an example. The material design guidelines state that you need this "View Group" if you have between 3 and 6 different actions. I'll try to look it up the page for you
  • Blackbelt
    Blackbelt over 8 years
    Have a look here
  • Sagar Devanga
    Sagar Devanga over 6 years
    In general scenario when there is only a FAB the snackbar automatically pushes the FAB and later its re-adjusted but when you use a FAB inside the linearLayout the snackbar overlaps the FAB. Did anyone face this issue ?