Inprevious post, I had talked about some popular designs of Floating Action Button (FAB) - a component of Design Support Library. Beside that, there is a design fromInbox application(developed by Google) which containing some FABs are combined into a group and they will be shown after the "representative button" clicked. This design called Floating Action Menu:
Up to now, there is no official component from Google which allows us making this design so we must use third-party library to building a Floating Action Menu (FAM). Fortunately, libraries to resolve this problem is not unpopular! In this post, I will use a third-party developed byDmytro Tarianyk Clans. It's very simple to implement and solving this problem quickly! DEMO VIDEO:
Import the library
Adding this dependency to your application levelbuild.gradle: dependencies { compile 'com.github.clans:fab:1.6.4'} Now, we have two objects calledFloatingActionMenuandFloatingActionButtonto build this layout.
Some important features
FloatingActionMenuhas some attributes in xml that we have to pay attention:
fab:menu_fab_label: Label for Menu button
fab_colorNormal,fab_colorPressed,fab_colorRipple: Change button color based on it's status.
fab_showAnimation,fab_hideAnimation: Animation when menu expand/collapse.
menu_labels_position: Position of buttons label (left/right).
//handling menu status (open or close) fam.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() { @Override public void onMenuToggle(boolean opened) { if (opened) { showToast("Menu is opened"); } else { showToast("Menu is closed"); } } });
//handling each floating action button clicked fabDelete.setOnClickListener(onButtonClick()); fabEdit.setOnClickListener(onButtonClick()); fabAdd.setOnClickListener(onButtonClick());
fam.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (fam.isOpened()) { fam.close(true); } } }); }