All Projects → leinardi → Floatingactionbuttonspeeddial

leinardi / Floatingactionbuttonspeeddial

Licence: apache-2.0
A Floating Action Button Speed Dial implementation for Android that follows the Material Design specification (https://material.io/components/buttons-floating-action-button#types-of-transitions)

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Floatingactionbuttonspeeddial

Expandable Fab
A highly customizable 'speed dial' FloatingActionButton implementation.
Stars: ✭ 56 (-95.19%)
Mutual labels:  material-design, android-ui, floatingactionbutton
Customfloatingactionbutton
This view is for replacement of standard Floating Action Button from Google Support Library. It is easy to use, customizable and you can also add text to button
Stars: ✭ 222 (-80.93%)
Mutual labels:  material-design, android-ui, floatingactionbutton
Materialdialog Android
📱Android Library to implement animated, 😍beautiful, 🎨stylish Material Dialog in android apps easily.
Stars: ✭ 602 (-48.28%)
Mutual labels:  material-design, android-ui
Music Player Go
🎶🎼 Very slim music player 👨‍🎤 100% made in Italy 🍕🌳🌞🍝🌄
Stars: ✭ 654 (-43.81%)
Mutual labels:  material-design, android-ui
Morphing Material Dialogs
Material dialog ❤️ morphing animation. An android kotlin UI library for building beautiful animations for converting a floating action button into a material dialog.
Stars: ✭ 806 (-30.76%)
Mutual labels:  material-design, android-ui
Android Material Design For Pre Lollipop
Various UI implementations, animations & effects based on Material Design compatible with pre Lollipop devices as well. (Work in progess)
Stars: ✭ 585 (-49.74%)
Mutual labels:  material-design, android-ui
Materialfavoritebutton
Animated favorite/star/like button
Stars: ✭ 586 (-49.66%)
Mutual labels:  material-design, android-ui
Slidetoact
A simple 'Slide to Unlock' Material widget for Android, written in Kotlin 📱🎨🦄
Stars: ✭ 783 (-32.73%)
Mutual labels:  material-design, android-ui
Bottomnavigation
This Library helps users to use Bottom Navigation Bar (A new pattern from google) with ease and allows ton of customizations
Stars: ✭ 4,299 (+269.33%)
Mutual labels:  material-design, android-ui
Sortabletableview
An Android library containing a simple TableView and an advanced SortableTableView providing a lot of customisation possibilities to fit all needs.
Stars: ✭ 1,019 (-12.46%)
Mutual labels:  material-design, android-ui
Bluetooth State View
Material design animated Bluetooth state view for Android
Stars: ✭ 36 (-96.91%)
Mutual labels:  material-design, android-ui
Lovelydialog
This library is a set of simple wrapper classes that are aimed to help you easily create fancy material dialogs.
Stars: ✭ 1,043 (-10.4%)
Mutual labels:  material-design, android-ui
Alerter
An Android Alerting Library
Stars: ✭ 5,213 (+347.85%)
Mutual labels:  material-design, android-ui
Cookiebar2
Android library for displaying text messages, notifications and alerts at the top or bottom of the screen. A great alternative for toast and snackbar alerts.
Stars: ✭ 499 (-57.13%)
Mutual labels:  material-design, android-ui
Guidetocustomviews
The ultimate guide to Android custom views
Stars: ✭ 595 (-48.88%)
Mutual labels:  material-design, android-ui
Materialpreferences
A highly flexible set of lovely looking views that provides functionality of preferences.
Stars: ✭ 495 (-57.47%)
Mutual labels:  material-design, android-ui
Motiontoast
🌈 A Beautiful Motion Toast Library for Kotlin Android
Stars: ✭ 767 (-34.11%)
Mutual labels:  material-design, android-ui
Aestheticdialogs
📱 An Android Library for 💫fluid, 😍beautiful, 🎨custom Dialogs.
Stars: ✭ 352 (-69.76%)
Mutual labels:  material-design, android-ui
Material Progressview
🔥A beautiful, gradual and simple used progress view for android.
Stars: ✭ 406 (-65.12%)
Mutual labels:  material-design, android-ui
Android Customtoast
Easy to use Custom Toast Library for Android
Stars: ✭ 24 (-97.94%)
Mutual labels:  material-design, android-ui

Floating Action Button Speed Dial

Maven metadata URI Travis GitHub license Stars

Android library providing an implementation of the Material Design Floating Action Button Speed Dial.

Features

  • [x] MinSdk 14
  • [x] Highly customizable (label, icon, ripple, fab and label background colors, themes support)
  • [x] Same animations as in Inbox by Gmail
  • [x] Option to have different icons for open/close state
  • [x] Optional overlay/touch guard layout
  • [x] Support for bottom, left and right menu expansion (left and right have no labels)
  • [x] Out-of-the box support for Snackbar behavior
  • [x] Optional support for RecyclerView and NestedScrollView behavior
  • [x] Support for VectorDrawable
  • [x] Easy to use

How to use

Gradle setup

Official releases

The library is available on Jcenter so no additonal repository is required.

Dependencies entry (latest version on Jcenter Maven metadata URI):

implementation "com.leinardi.android:speed-dial:3.1.1"

Snapshots (development branch)

You can use JitPack to test the latest master (remember that master is the development branch and can be unstable or completely broken).

Add the JitPack repository to your build file:

maven { url 'https://jitpack.io' }

Add the dependency

implementation 'com.github.leinardi:FloatingActionButtonSpeedDial:master-SNAPSHOT'

Basic use

SpeedDialView

Add the SpeedDialView to your layout:

<com.leinardi.android.speeddial.SpeedDialView
    android:id="@+id/speedDial"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    app:sdMainFabClosedSrc="@drawable/ic_add_white_24dp" />

Action items

Add the items to the SpeedDialView:

val speedDialView = findViewById<SpeedDialView>(R.id.speedDial)
speedDialView.addActionItem(
    SpeedDialActionItem.Builder(R.id.fab_no_label, R.drawable.ic_link_white_24dp)
        .create())

If the color customization is not requested, it is also possible to inflate the Action items form a Menu Resource:

speedDialView.inflate(R.menu.menu_speed_dial)

Only the attributes android:id, android:icon and android:title are supported.

Click listeners

Add the click listeners:

speedDialView.setOnActionSelectedListener(SpeedDialView.OnActionSelectedListener { actionItem ->
    when (actionItem.id) {
        R.id.fab_no_label -> {
            showToast("No label action clicked!\nClosing with animation")
            speedDialView.close() // To close the Speed Dial with animation
            return@OnActionSelectedListener true // false will close it without animation
        }
    }
    false
})

Optional steps

Add the main action click listener

speedDialView.setOnChangeListener(object : SpeedDialView.OnChangeListener {
    override fun onMainActionSelected(): Boolean {
        showToast("Main action clicked!")
        return false // True to keep the Speed Dial open
    }

    override fun onToggleChanged(isOpen: Boolean) {
        Log.d(TAG, "Speed dial toggle state changed. Open = $isOpen")
    }
})

Customizing the items

The SpeedDialActionItem.Builder provides several setters to customize the aspect of one item:

speedDialView.addActionItem(SpeedDialActionItem.Builder(R.id.fab_custom_color, drawable)
        .setFabBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.material_white_1000, getTheme()))
        .setFabImageTintColor(ResourcesCompat.getColor(getResources(), R.color.inbox_primary, getTheme()))
        .setLabel(getString(R.string.label_custom_color))
        .setLabelColor(Color.WHITE)
        .setLabelBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.inbox_primary, getTheme()))
        .setLabelClickable(false)
        .create())

Is is also possible to specify a theme to easily change the FAB background and ripple effect color:

speedDialView.addActionItem(SpeedDialActionItem.Builder(R.id.fab_custom_theme, R.drawable.ic_theme_white_24dp)
        .setLabel(getString(R.string.label_custom_theme))
        .setTheme(R.style.AppTheme_Purple)
        .create())
<style name="AppTheme.Purple" parent="AppTheme">
    <item name="colorPrimary">@color/material_purple_500</item>
    <item name="colorPrimaryDark">@color/material_purple_700</item>
    <item name="colorAccent">@color/material_purple_a700</item>
    <item name="colorControlHighlight">@color/material_purple_200</item>
</style>

Adding an overlay/touch guard when the menu is open (like Inbox by Gmail)

You simply need to add the SpeedDialOverlayLayout to your layout:

<com.leinardi.android.speeddial.SpeedDialOverlayLayout
    android:id="@+id/overlay"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

and then provide the instance of that layout to the SpeedDialView:

<com.leinardi.android.speeddial.SpeedDialView
    android:id="@+id/speedDial"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:sdMainFabClosedSrc="@drawable/ic_add_white_24dp"
    app:sdOverlayLayout="@id/overlay" />

or

val overlayLayout = findViewById<SpeedDialOverlayLayout>(R.id.overlay)
speedDialView.setSpeedDialOverlayLayout(overlayLayout)

Hiding the FAB when scrolling a RecyclerView or a NestedScrollView

Just apply the ScrollingViewSnackbarBehavior to the SpeedDialView. This can be done via XML using the convenience string resource @string/speeddial_scrolling_view_snackbar_behavior:

<com.leinardi.android.speeddial.SpeedDialView
    android:id="@+id/speedDial"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/speeddial_scrolling_view_snackbar_behavior" />

Or programmatically:

val params = speedDialView.layoutParams as CoordinatorLayout.LayoutParams
params.behavior = SpeedDialView.ScrollingViewSnackbarBehavior()
speedDialView.requestLayout()

NB: for the behaviors to work, SpeedDialView needs to be a direct child of CoordinatorLayout

Disabling SnackbarBehavior

Since the SnackbarBehavior is enabled by default and, afaik, it is not possible to remove a Behavior, simply use apply the SpeedDialView.NoBehavior instead:

val params = speedDialView.layoutParams as CoordinatorLayout.LayoutParams
params.behavior = SpeedDialView.NoBehavior()
speedDialView.requestLayout()

Sample project

A fully working example is available here.

Demo

Video

https://www.youtube.com/watch?v=tWowiF5ElAg

Sample app

Get it on the Play Store

Screenshots

API 27, API 16, bottom and left expansion

FAQ

How can I create a new resource ID, required by the SpeedDialActionItem.Builder?

It can be done in XML using the <item type="id" />:

<resources>
    <item name="fab_action1" type="id" />
    <item name="fab_action2" type="id" />
    <item name="fab_action3" type="id" />
    <item name="fab_action4" type="id" />
</resources>

How can I change the maximum length of the label?

You can set a different value for the max length of the label overriding sd_label_max_width:

<dimen name="sd_label_max_width">240dp</dimen>

More info here.

How can I change the color of the overlay / touch guard layout?

The color of the SpeedDialOverlayLayout can be changed simply using the android:background attribute or, programmatically, using the equivalent setter like any other view.

How can I prevent the overlay / touch guard layout from going over the Toolbar inside a CoordinatorLayout?

It can be done using the attribute app:layout_behavior="@string/appbar_scrolling_view_behavior":

<com.leinardi.android.speeddial.SpeedDialOverlayLayout
    android:id="@+id/overlay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

Changelog

See the CHANGELOG.md

Credits

This project is based on floating-action-menu by ArthurGhazaryan.

Licenses

Copyright 2019 Roberto Leinardi.

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements.  See the NOTICE file distributed with this work for
additional information regarding copyright ownership.  The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License.  You may obtain a copy of
the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
License for the specific language governing permissions and limitations under
the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].