Convert Figma logo to code with AI

makovkastar logoFloatingActionButton

[DEPRECATED] Android floating action button

4,008
820
4,008
79

Top Related Projects

Floating Action Button for Android based on Material Design specification

Android Floating Action Button based on Material Design specification

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

FloatingActionButton is an Android library that provides an implementation of the Floating Action Button (FAB) component from Material Design. It offers customizable FABs with features like shadows, animations, and the ability to attach FABs to other views.

Pros

  • Easy integration with existing Android projects
  • Customizable appearance and behavior
  • Supports pre-Lollipop devices (API 14+)
  • Includes additional features like attaching FABs to lists and scrollviews

Cons

  • Not actively maintained (last update was in 2016)
  • May not include the latest Material Design guidelines and features
  • Limited documentation and examples
  • Potential compatibility issues with newer Android versions

Code Examples

  1. Creating a basic FloatingActionButton:
FloatingActionButton fab = new FloatingActionButton(context);
fab.setColorNormal(Color.BLUE);
fab.setColorPressed(Color.DARK_BLUE);
fab.setIcon(R.drawable.ic_add);
layout.addView(fab);
  1. Attaching a FAB to a ListView:
ListView listView = findViewById(R.id.list_view);
FloatingActionButton fab = findViewById(R.id.fab);
fab.attachToListView(listView);
  1. Adding a click listener to the FAB:
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // Handle FAB click
    }
});

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:
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // Handle FAB click
    }
});

Competitor Comparisons

Floating Action Button for Android based on Material Design specification

Pros of android-floating-action-button

  • More customizable appearance with options for icon, color, and size
  • Supports multiple action buttons and menu-style layouts
  • Actively maintained with recent updates and bug fixes

Cons of android-floating-action-button

  • Slightly more complex implementation due to additional features
  • Larger library size compared to FloatingActionButton
  • May require more configuration for basic use cases

Code Comparison

FloatingActionButton:

<com.getbase.floatingactionbutton.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    fab:fab_icon="@drawable/ic_action_add"
    fab:fab_colorNormal="@color/primary"
    fab:fab_colorPressed="@color/primary_dark" />

android-floating-action-button:

<com.zendesk.floatingactionbutton.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:fab_icon="@drawable/ic_add"
    app:fab_colorNormal="@color/accent"
    app:fab_colorPressed="@color/accent_dark"
    app:fab_size="normal" />

Both libraries offer similar basic functionality for creating floating action buttons in Android applications. FloatingActionButton provides a simpler implementation for basic use cases, while android-floating-action-button offers more advanced features and customization options. The choice between the two depends on the specific requirements of your project and the level of complexity you're willing to work with.

Android Floating Action Button based on Material Design specification

Pros of FloatingActionButton (Clans)

  • More customization options, including shadow color and size
  • Supports mini FABs and labels
  • Actively maintained with recent updates

Cons of FloatingActionButton (Clans)

  • Slightly more complex implementation due to additional features
  • May require more configuration to achieve desired appearance

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_size="normal"
    fab:fab_icon="@drawable/ic_add" />

The Clans version offers more attributes for customization, such as fab_colorNormal and fab_size, while the makovkastar version is simpler but less flexible. Both libraries provide similar basic functionality, but Clans offers more advanced features and customization options at the cost of slightly increased complexity.

A multi-functional FAB component with customizable options

Pros of faboptions

  • More customizable with additional options for button appearance and behavior
  • Supports multiple action buttons in a single FAB
  • Smoother animations and transitions between states

Cons of faboptions

  • Slightly more complex implementation due to additional features
  • May require more setup time for basic use cases
  • Less documentation and community support compared to FloatingActionButton

Code Comparison

FloatingActionButton:

<com.getbase.floatingactionbutton.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:fab_colorNormal="@color/primary"
    app:fab_icon="@drawable/ic_action" />

faboptions:

<com.joaquimley.faboptions.FabOptions
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:button_menu="@menu/menu_fab_options"
    app:background_color="@color/primary"
    app:button_color="@color/accent" />

Both libraries provide easy-to-use implementations of Floating Action Buttons, but faboptions offers more advanced features and customization options. FloatingActionButton is simpler to implement for basic use cases, while faboptions provides greater flexibility for complex designs. The choice between the two depends on the specific requirements of your project and the level of customization needed.

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 with multiple action buttons
  • Provides customizable animations and transitions
  • Supports both XML and programmatic configuration

Cons of FloatingActionButtonSpeedDial

  • May have a steeper learning curve due to additional features
  • Potentially larger library size compared to the simpler FloatingActionButton

Code Comparison

FloatingActionButton:

<com.getbase.floatingactionbutton.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    fab:fab_icon="@drawable/ic_action"
    fab:fab_colorNormal="@color/primary"
    fab:fab_colorPressed="@color/primary_dark" />

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"
    app:sdMainFabOpenedSrc="@drawable/ic_close" />

The FloatingActionButtonSpeedDial library provides more advanced functionality with its SpeedDialView, allowing for multiple action buttons and customizable animations. However, this comes at the cost of a potentially more complex implementation. The FloatingActionButton library offers a simpler approach for basic floating action button needs.

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

DEPRECATED

Use the FloatingActionButton from the support library instead.

FloatingActionButton

Android Arsenal

Description

Android floating action button which reacts on scrolling events. Becomes visible when an attached target is scrolled up and invisible when scrolled down.

Demo

Demo

FloatingActionButton Demo on Google Play Store

Integration

1) Add as a dependency to your build.gradle:

dependencies {
    compile 'com.melnykov:floatingactionbutton:1.3.0'
}

2) Add the com.melnykov.fab.FloatingActionButton to your layout XML file. The button should be placed in the bottom right corner of the screen. The width and height of the floating action button are hardcoded to 56dp for the normal and 40dp for the mini button as specified in the guidelines.

<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="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    <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_action_content_new"
            fab:fab_colorNormal="@color/primary"
            fab:fab_colorPressed="@color/primary_pressed"
            fab:fab_colorRipple="@color/ripple" />
</FrameLayout>

3) Attach the FAB to AbsListView, RecyclerView or ScrollView :

ListView listView = (ListView) findViewById(android.R.id.list);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.attachToListView(listView);

Check the sample project to see how to use custom listeners if you need to track scroll events.

4) Add the namespace xmlns:fab="http://schemas.android.com/apk/res-auto" to your layout file.

  • Set the button type (normal or mini) via the fab_type xml attribute (default is normal):

    fab:fab_type="mini"
    

    or

    fab.setType(FloatingActionButton.TYPE_MINI);
    
  • Set the normal and pressed colors via the xml attributes:

    fab:fab_colorNormal="@color/primary"
    fab:fab_colorPressed="@color/primary_pressed"
    

    or

    fab.setColorNormal(getResources().getColor(R.color.primary));
    fab.setColorPressed(getResources().getColor(R.color.primary_pressed));
    
  • Enable/disable the button shadow with the fab_shadow xml attribite (it's enabled by default):

    fab:fab_shadow="false"
    

    or

    fab.setShadow(false);
    
  • Show/hide the button expliciltly:

    fab.show();
    fab.hide();
    
    fab.show(false); // Show without an animation
    fab.hide(false); // Hide without an animation
    
  • Specify the ripple color for API 21+:

    fab:fab_colorRipple="@color/ripple"
    

    or

    fab.setColorRipple(getResources().getColor(R.color.ripple));
    

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

Changelog

Version 1.3.0

  • Add the disabled state for the FAB (thanks to Aleksey Malevaniy);
  • Fix shadow assets. Rename shadow drawables with a prefix;
  • Generate default pressed and ripple colors (thanks to Aidan Follestad).

Version 1.2.0

  • Respect an elevation set manually for the FAB;
  • Don't emit a scroll when the listview is empty;
  • Add an ability to attach normal listeners for scroll operations (thanks to Bill Donahue).

Version 1.1.0:

  • Do not ignore negative margins on pre-Lollipop;
  • Disable clicks on the FAB when it's hidden on pre-Honeycomb;
  • Some shadow tuning.

Version 1.0.9:

  • Support API 7;
  • Fixed extra margins on pre-Lollipop devices;
  • Fixed mini FAB size;
  • Updated shadow assets to more accurately match 8dp elevation.

Version 1.0.8:

  • ATTENTION! Breaking changes for custom listeners. Check an updated sample how to use them.
  • Added support for the ScrollView;
  • Significantly optimized scroll detection for the RecyclerView;
  • Fixed laggy animation for a list view with items of different height;
  • Added isVisible getter;
  • Deleted deprecated methods.

Version 1.0.7:

  • Updated shadow assets to better match material design guidelines;
  • Make FabOnScrollListener and FabRecyclerOnViewScrollListener implement ScrollDirectionListener for easier custom listeners usage.

Version 1.0.6:

  • Added support for the RecyclerView;
  • Added ripple effect and elevation for API level 21.

Thanks to Aidan Follestad.

Version 1.0.5:

  • Updated shadow to more accurately match the material design spec;

Version 1.0.4:

  • Allow a custom OnScrollListeners to be attached to a list view;
  • Work properly with list of different height rows;
  • Ignore tiny shakes of fingers.

Version 1.0.3:

  • Add methods to show/hide without animation;
  • Fix show/hide when a view is not measured yet.

Applications using FloatingActionButton

Please ping me or send a pull request if you would like to be added here.

IconApplicationIconApplication
Finger Gesture LauncherVocabletrainer
Lanekeep GPS Mileage TrackerScore It
Перезвони мнеApp Swap
QKSMS - Quick Text MessengerUninstaller - Beta Version
Device ControlConfide
Date NightJair Player The Music Rainbow
Taskr - Lista de TareasFestivos: ¡Conoce el mundo!
nowPaperVicious chain - Don't do that!
My Football StatsThe ScoreBoard
NavPointJust Reminder
Early NotesRanch - Smart Tip Calculator
Thiengo CalopsitaTinycore - CPU, RAM monitor
Battery Aid Saver & ManagerGameRaven
Polaris OfficeCall Utils
Colorful NoteCallSticker - заметки звонка

Links

Country flag icons used in the sample are taken from www.icondrawer.com

License

The MIT License (MIT)

Copyright (c) 2014 Oleksandr Melnykov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.