Convert Figma logo to code with AI

Clans logoFloatingActionButton

Android Floating Action Button based on Material Design specification

5,225
1,132
5,225
231

Top Related Projects

Floating Action Button for Android based on Material Design specification

[DEPRECATED] Android floating action button

A multi-functional FAB component with customizable options

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)

Quick Overview

Clans/FloatingActionButton is an Android library that provides an enhanced implementation of the Floating Action Button (FAB) component. It extends the functionality of the standard FAB by offering additional features such as labels, multiple actions, and customizable animations.

Pros

  • Easy integration with existing Android projects
  • Highly customizable appearance and behavior
  • Supports multiple action buttons with labels
  • Smooth animations and transitions

Cons

  • May require additional setup compared to the standard FAB
  • Potential performance impact with complex animations
  • Limited documentation for advanced use cases
  • Dependency on specific Android support libraries

Code Examples

Adding a basic FloatingActionButton:

val fab = FloatingActionButton.Builder(this)
    .setContentView(R.drawable.ic_add)
    .build()

Creating a FloatingActionButton with a label:

val labeledFab = FloatingActionButton.Builder(this)
    .setContentView(R.drawable.ic_edit)
    .setLabel("Edit")
    .build()

Implementing multiple actions:

val menuBuilder = FloatingActionMenu.Builder(this)
    .addSubActionView(FloatingActionButton.Builder(this)
        .setContentView(R.drawable.ic_share)
        .setLabel("Share")
        .build())
    .addSubActionView(FloatingActionButton.Builder(this)
        .setContentView(R.drawable.ic_delete)
        .setLabel("Delete")
        .build())
    .setAnimation(FlipAnimation())
    .attachTo(mainFab)

Getting Started

  1. Add the dependency to your build.gradle file:
dependencies {
    implementation 'com.github.clans:fab:1.6.4'
}
  1. Add the FloatingActionButton to your layout XML:
<com.github.clans.fab.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="16dp"
    app:fab_colorNormal="@color/colorPrimary"
    app:fab_colorPressed="@color/colorPrimaryDark"
    app:fab_icon="@drawable/ic_add" />
  1. Initialize and customize the FAB in your Activity or Fragment:
val fab: FloatingActionButton = findViewById(R.id.fab)
fab.setOnClickListener {
    // Handle FAB click
}

Competitor Comparisons

Floating Action Button for Android based on Material Design specification

Pros of android-floating-action-button

  • Lightweight and focused solely on FAB functionality
  • Simpler implementation for basic FAB use cases
  • Maintained by Zendesk, a well-known company in the customer service industry

Cons of android-floating-action-button

  • Less customization options compared to FloatingActionButton
  • Fewer features and animations available out-of-the-box
  • Less active development and community engagement

Code Comparison

FloatingActionButton:

FloatingActionButton fab = new FloatingActionButton.Builder(this)
    .setContentView(iconView)
    .setBackgroundDrawable(R.drawable.button_action_red_selector)
    .build();

android-floating-action-button:

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setIcon(R.drawable.ic_action_add);
fab.setColorNormalResId(R.color.primary);
fab.setColorPressedResId(R.color.primary_dark);

Both libraries provide easy ways to create and customize FABs, but FloatingActionButton offers more advanced customization options and features. The android-floating-action-button library focuses on simplicity and ease of use for basic FAB implementations. The choice between the two depends on the specific requirements of your project and the level of customization needed.

[DEPRECATED] Android floating action button

Pros of FloatingActionButton (makovkastar)

  • Simpler implementation with fewer features, making it easier to integrate for basic use cases
  • Lighter weight library with a smaller footprint
  • Follows Material Design guidelines more closely

Cons of FloatingActionButton (makovkastar)

  • Less customization options compared to the Clans version
  • Fewer animation capabilities and effects
  • Limited support for additional features like labels or multiple action buttons

Code Comparison

FloatingActionButton (makovkastar):

<com.melnykov.fab.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_margin="16dp"
    android:src="@drawable/ic_add" />

FloatingActionButton (Clans):

<com.github.clans.fab.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_margin="16dp"
    fab:fab_colorNormal="@color/colorPrimary"
    fab:fab_colorPressed="@color/colorPrimaryDark"
    fab:fab_icon="@drawable/ic_add" />

The Clans version offers more customization options directly in the XML layout, such as color attributes and icon specification.

A multi-functional FAB component with customizable options

Pros of faboptions

  • More compact design, combining FAB with menu options
  • Smoother animations and transitions
  • Easier to implement custom behaviors

Cons of faboptions

  • Less customization options for individual FAB appearance
  • Limited to a single row of menu items
  • Fewer stars and contributors, potentially less community support

Code Comparison

FloatingActionButton:

FloatingActionButton fab = new FloatingActionButton.Builder(this)
    .setContentView(iconView)
    .setBackgroundDrawable(drawable)
    .build();

faboptions:

fab_options.setButtonsMenu(R.menu.menu_fab_options)
fab_options.setOnClickListener { view ->
    when (view.id) {
        R.id.faboptions_favorite -> // Handle favorite action
        R.id.faboptions_textsms -> // Handle textsms action
    }
}

FloatingActionButton offers more granular control over the FAB's appearance and behavior, while faboptions provides a more streamlined approach for combining FAB with menu options. FloatingActionButton is better suited for complex custom FAB implementations, whereas faboptions excels in scenarios where a quick menu-style FAB is needed with minimal setup.

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)

Pros of FloatingActionButtonSpeedDial

  • Offers a speed dial functionality, allowing multiple actions to be associated with a single FAB
  • Provides more customization options for the speed dial menu items
  • Supports both Material Design 1 and 2 styles

Cons of FloatingActionButtonSpeedDial

  • May have a steeper learning curve due to additional features and configurations
  • Potentially larger library size due to extended functionality
  • Less suitable for simple, single-action FAB implementations

Code Comparison

FloatingActionButton:

<com.github.clans.fab.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_add" />

FloatingActionButtonSpeedDial:

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

The code comparison shows that FloatingActionButtonSpeedDial uses a different view class (SpeedDialView) and attribute namespace (app:sd*) for configuration, reflecting its extended functionality compared to the simpler FloatingActionButton implementation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

WARNING! FURTHER DEVELOPMENT AND SUPPORT IS DISCONTINUED.

FloatingActionButton

Maven Central Android Arsenal

Yet another implementation of Floating Action Button for Android with lots of features.

Requirements

The library requires Android API Level 14+.

Demo

Watch a short Demo Video on YouTube or try it using Android simulator in the browser on Appetize.io.
Sample APK can be found in Releases section.

Screenshots

Main screen Menu closed Menu default opened Menu custom opened Menu mini opened Menu right opened Menu down opened Progress background Progress no background

Features

  • Ripple effect on Android Lollipop devices
  • Option to set custom normal/pressed/ripple colors
  • Option to set custom shadow color and offsets
  • Option to disable shadow for buttons and (or) labels
  • Option to set custom animations
  • Option to set custom icon drawable
  • Support for normal 56dp and mini 40dp button sizes
  • Custom FloatingActionMenu icon animations
  • Option to expand menu up and down
  • Option to show labels to the left and to the right of the menu
  • Option to show circle progress on FloactinActionButton
  • Option to add button to the FloatingActionMenu programmatically
  • Option to dim the FloatinActionMenu's background
  • Option to remove all buttons from the FloatingActionMenu
  • Option to set a label for the FloatingActionMenu's button

Usage

Add a dependency to your build.gradle:

dependencies {
    compile 'com.github.clans:fab:1.6.4'
}

Add the com.github.clans.fab.FloatingActionButton to your layout XML file.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.github.clans.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="8dp"
        android:layout_marginRight="8dp"
        android:src="@drawable/ic_menu"
        fab:fab_colorNormal="@color/app_primary"
        fab:fab_colorPressed="@color/app_primary_pressed"
        fab:fab_colorRipple="@color/app_ripple"/>

</FrameLayout>

You can set an icon for the FloatingActionButton using android:src xml attribute. Use drawables of size 24dp as specified by guidlines. Icons of desired size can be generated with Android Asset Studio.

Floating action button

Here are all the FloatingActionButton's xml attributes with their default values which means that you don't have to set all of them:

<com.github.clans.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="8dp"
        android:layout_marginRight="8dp"
        android:src="@drawable/your_icon_drawable"
        app:fab_colorNormal="#DA4336"
        app:fab_colorPressed="#E75043"
        app:fab_colorRipple="#99FFFFFF"
        app:fab_showShadow="true"
        app:fab_shadowColor="#66000000"
        app:fab_shadowRadius="4dp"
        app:fab_shadowXOffset="1dp"
        app:fab_shadowYOffset="3dp"
        app:fab_size="normal"
        app:fab_showAnimation="@anim/fab_scale_up"
        app:fab_hideAnimation="@anim/fab_scale_down"
        app:fab_label=""
        app:fab_progress_color="#FF009688"
        app:fab_progress_backgroundColor="#4D000000"
        app:fab_progress_indeterminate="false"
        app:fab_progress_max="100"
        app:fab_progress="0"
        app:fab_progress_showBackground="true"/>

All of these FloatingActionButton's attributes has their corresponding getters and setters. So you can set them programmatically.

Floating action menu

Here are all the FloatingActionMenu's xml attributes with their default values which means that you don't have to set all of them:

<com.github.clans.fab.FloatingActionMenu
        android:id="@+id/menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        fab:menu_fab_size="normal"
        fab:menu_showShadow="true"
        fab:menu_shadowColor="#66000000"
        fab:menu_shadowRadius="4dp"
        fab:menu_shadowXOffset="1dp"
        fab:menu_shadowYOffset="3dp"
        fab:menu_colorNormal="#DA4336"
        fab:menu_colorPressed="#E75043"
        fab:menu_colorRipple="#99FFFFFF"
        fab:menu_animationDelayPerItem="50"
        fab:menu_icon="@drawable/fab_add"
        fab:menu_buttonSpacing="0dp"
        fab:menu_labels_margin="0dp"
        fab:menu_labels_showAnimation="@anim/fab_slide_in_from_right"
        fab:menu_labels_hideAnimation="@anim/fab_slide_out_to_right"
        fab:menu_labels_paddingTop="4dp"
        fab:menu_labels_paddingRight="8dp"
        fab:menu_labels_paddingBottom="4dp"
        fab:menu_labels_paddingLeft="8dp"
        fab:menu_labels_padding="8dp"
        fab:menu_labels_textColor="#FFFFFF"
        fab:menu_labels_textSize="14sp"
        fab:menu_labels_cornerRadius="3dp"
        fab:menu_labels_colorNormal="#333333"
        fab:menu_labels_colorPressed="#444444"
        fab:menu_labels_colorRipple="#66FFFFFF"
        fab:menu_labels_showShadow="true"
        fab:menu_labels_singleLine="false"
        fab:menu_labels_ellipsize="none"
        fab:menu_labels_maxLines="-1"
        fab:menu_labels_style="@style/YourCustomLabelsStyle"
        fab:menu_labels_position="left"
        fab:menu_openDirection="up"
        fab:menu_backgroundColor="@android:color/transparent"
        fab:menu_fab_label="your_label_here"
        fab:menu_fab_show_animation="@anim/my_show_animation"
        fab:menu_fab_hide_animation="@anim/my_hide_animation">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/menu_item"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_star"
            fab:fab_size="mini"
            fab:fab_label="Menu item 1" />

    </com.github.clans.fab.FloatingActionMenu>

If you're using custom style for labels - other labels attributes will be ignored.

Labels shadow preferences depends on their corresponding FloatingActionButtons' shadow preferences.

For more usage examples check the sample project.

Changelog

Please see the Changelog page to see what's recently changed.

Credits

I used android-floating-action-button library by Jerzy Chalupski as a base for development.

License

Copyright 2015 Dmytro Tarianyk

Licensed 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.