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

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

Posted by: admin June 15, 2020 Leave a comment

Questions:

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" />
How to&Answers:

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