fab-speed-dial

by yavski

FAB flinging out actionable menu items using the Speed dial metaphor

467 Stars 122 Forks Last release: almost 4 years ago (1.0.7) Apache License 2.0 67 Commits 8 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

fab-speed-dial

Android Arsenal Android Gems

A simple library marrying together FAB + menu resources + Speed dial metaphor from Material Design.

Similarly tо NavigationView and ActionBar, FabSpeedDial makes use of menu resources in order to present a list of actionable buttons. This makes the library somewhat familiar to use and easy to integrate. The library runs on Android 2.2 (API 8) onwards.

Gettting started

Add the dependency to gradle.build
dependencies {
    compile 'io.github.yavski:fab-speed-dial:1.0.6'
}
Define a menu resource

    
    
    

Add FabSpeedDial to your layout xml
<io.github.yavski.fabspeeddial.fabspeeddial android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" app:fabgravity="bottom_end" app:fabmenu="@menu/menu_main" app:minifabbackgroundtint="@android:color/white" app:minifabdrawabletint="?attr/colorPrimaryDark" app:minifabtitletextcolor="?attr/colorPrimaryDark"></io.github.yavski.fabspeeddial.fabspeeddial>
Result

In order to save the menu open/closed state, you must define an id to the FabSpeedDial, otherwise if you rotate the device the state won't be persisted.

Events

As with all menus, you have a callback just before the list of actionable items are presented. The callback allows you to update your menu items, or not show the menu altogether.

        FabSpeedDial fabSpeedDial = (FabSpeedDial) findViewById(R.id.fab_speed_dial);
        fabSpeedDial.setMenuListener(new SimpleMenuListenerAdapter() {
            @Override
            public boolean onPrepareMenu(NavigationMenu navigationMenu) {
                // TODO: Do something with yout menu items, or return false if you don't want to show them
                return true;
            }
        });

Similarly, in order to be notified about a selection:

        FabSpeedDial fabSpeedDial = (FabSpeedDial) findViewById(R.id.fab_speed_dial);
        fabSpeedDial.setMenuListener(new SimpleMenuListenerAdapter() {
            @Override
            public boolean onMenuItemSelected(MenuItem menuItem) {
               //TODO: Start some activity
              return false;
            }
        });

Customisation

Multi-colored fabs

Define an integer-array resource that contains the colors you want to use in the order of the items you want colored:

    
    @android:color/holo_red_dark
    
    @android:color/holo_purple
    
    @android:color/holo_green_light

Make sure you also assign android:orderInCategory to each menu item in your menu.xml in the same 0-based order.

To provide the color array to the menu items use the following attributes:

miniFabTitleTextColorList
and
miniFabBackgroundTintList
. Note - if you've used
miniFabTitleTextColor
and
miniFabBackgroundTint
they will be overriden by the color arrays.
Result

Position

In order to change the position of the view, use the standard android APIs to position FabSpeedDial within your ViewGroup and be sure to assign

fabGravity
a relevant value.

Basic styling

As a rule of thumb, attributes prepended with fab, i.e.

fabDrawable
, refer to the normsal-sized FAB view; attribtues prepended with miniFab refer to the mini-sized FAB views in the list.

The following attribtues are supported:

| FabSpeedDial| Android | Desscription | | ------------- |-------------|-----| | app:fabDrawable | android:src | Sets the icon drawable of the main FAB | | app:fabDrawableTint | android:tint | Tints the icon drawable of the main FAB | | app:fabBackgroundTint | android:backgroundTint | Tints the background colour of the main FAB | | app:miniFabDrawableTint | android:tint | Tints the icon drawable of the mini FAB(s) | | app:miniFabBackgroundTint | android:backgroundTint | Tints the background colour of the mini FAB(s) | |app:miniFabBackgroundTintList | | An array containing the background colors for each of the mini FABs. |app:miniFabTitleTextColor| android:textColor | Sets the color of the title of the mini FAB. | |app:miniFabTitleTextColorList|| An array containing the colors for each of the titles of the mini FABs. | app:miniFabTitleBackgroundTint | android:backgroundTint | Tints the background colour of the title(s) of the mini FAB(s) | | app:miniFabTitlesEnabled | | Convinience for hiding the tilte(s) of the mini FAB(s) | | app:touchGuard | | Hide FAB when touching out of its bounds | | app:touchGuardDrawable | android:background | Sets background to the container of FAB

Caveats

If you have used FloatingActionButton, CoordinatorLayout, and both combined, you are most probably aware that: * Internally, FAB has two main implementations: one for SDK >= 21, one for earlier versions; the one for older versions uses extra padding in order to draw shadows; you don't need to account for the extra padding as the library takes care of it however do check your layouts/dimensions to avoid mis-positioned views. * When used in a CoordinatorLayout, FAB is known to have its margin values ignored / misused under certain circumstances; as a workaround the library always adds left or right margin values (depending on gravity), taking into account the SDK version too.

License

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.