How to Create Expandable Floating Action Button(FAB) Menu

Updated 24 January 2024

Save

A Floating Action Button(fab) displays the primary action in an application. It is a round icon button that’s elevated above other page content. Floating action buttons come in a default and mini size.

Floating action buttons provide quick access to important or common actions within an app. They have a variety of uses, including:

Floating action buttons adjust their position and visibility in response to other UI elements on the screen.

Sometime we need to create expandable floating Button. On click of floating button some other floating button should be open .

For your reference i have added some code –

first we need to define all FAB at same place so they overlap each other, remember on top the FAB should be that you want to click and to show other. eg:

Now in the java class just define all your FAB and perform the click like shown below:

Now use the animation().translationY() to animate your FAB,I prefer you to use the attribute of this method in DP since only using an int will effect the display compatibility with higher resolution or lower resolution. as shown below:

Now define the above mentioned dimension inside res->values->dimens.xml as shown below:

FAB Example

NOTE : fab1, fab2, fab3 buttons in the illustration above are declared as Global variables so that these can be used in other functions as well.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


6 comments

  • Katharina S.
  • Ayhan
  • Ayhan
    • Pavel
  • Delancy J.
    • anchit (Moderator)
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home