Android library that provides the floating action button to sheet transition from Google's Material Design.

Overview

MaterialSheetFab

Maven Central Codacy Badge GitHub license Android Arsenal Android Weekly

Library that implements the floating action button to sheet transition from Google's Material Design documentation. It can be used with any FAB library on Android 4.0+ (API levels >= 14).

Transition

Installation

Gradle

Add the dependency (available from mavenCentral and jcenter) to your build.gradle:

implementation 'com.gordonwong:material-sheet-fab:1.2.1'

Proguard

Modify your proguard configuration (if your app is using Proguard).

-keep class io.codetail.animation.arcanimator.** { *; }

Usage

Implement the FAB:

You can use any FAB library as long as it implements the AnimatedFab interface.

import android.support.design.widget.FloatingActionButton;

public class Fab extends FloatingActionButton implements AnimatedFab {

   /**
    * Shows the FAB.
    */
    @Override
    public void show() {
        show(0, 0);
    }

    /**
     * Shows the FAB and sets the FAB's translation.
     *
     * @param translationX translation X value
     * @param translationY translation Y value
     */
    @Override
    public void show(float translationX, float translationY) {
        // NOTE: Using the parameters is only needed if you want
        // to support moving the FAB around the screen.
        // NOTE: This immediately hides the FAB. An animation can 
        // be used instead - see the sample app.
        setVisibility(View.VISIBLE);
    }

    /**
     * Hides the FAB.
     */
    @Override
    public void hide() {
        // NOTE: This immediately hides the FAB. An animation can
        // be used instead - see the sample app.
        setVisibility(View.INVISIBLE);
    }
}

Modify the layouts:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

   <!-- Your FAB implementation -->
   <path.to.your.fab
        android:id="@+id/fab"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true" />

    <!-- Overlay that dims the screen -->
    <com.gordonwong.materialsheetfab.DimOverlayFrameLayout
        android:id="@+id/overlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- Circular reveal container for the sheet -->
    <io.codetail.widget.RevealLinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="end|bottom"
        android:orientation="vertical">

        <!-- Sheet that contains your items -->
        <android.support.v7.widget.CardView
            android:id="@+id/fab_sheet"
            android:layout_width="250dp"
            android:layout_height="300dp">
            
            <!-- TODO: Put your sheet items here -->
            
        </android.support.v7.widget.CardView>
    </io.codetail.widget.RevealLinearLayout>
</RelativeLayout>

Initialize the MaterialSheetFab:

This can be in your Activity or Fragment.

public class MaterialSheetFabActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Fab fab = (Fab) findViewById(R.id.fab);
        View sheetView = findViewById(R.id.fab_sheet);
        View overlay = findViewById(R.id.dim_overlay);
        int sheetColor = getResources().getColor(R.color.fab_sheet_color);
        int fabColor = getResources().getColor(R.color.fab_color);

        // Initialize material sheet FAB
        materialSheetFab = new MaterialSheetFab<>(fab, sheetView, overlay,
            sheetColor, fabColor);
    }
}

Optional:

Close sheet on back button:

@Override
public void onBackPressed() {
    if (materialSheetFab.isSheetVisible()) {
        materialSheetFab.hideSheet();
    } else {
        super.onBackPressed();
    }
}

Listen to events:

materialSheetFab.setEventListener(new MaterialSheetFabEventListener() {
    @Override
    public void onShowSheet() {
        // Called when the material sheet's "show" animation starts.
    }
    
    @Override
    public void onSheetShown() {
        // Called when the material sheet's "show" animation ends.
    }

    @Override
    public void onHideSheet() {
        // Called when the material sheet's "hide" animation starts.
    }
     
    public void onSheetHidden() {
        // Called when the material sheet's "hide" animation ends.
    }
});

Move the FAB around the screen (this is useful for coordinating with snackbars):

materialSheetFab.showFab(translationX, translationY);

Sample app

Get it on Google Play

Sample 1 Sample 2

Take a look at the sample code and try the app.

Apps using MaterialSheetFab

Feel free to open a pull request to include your app here.

Icon App
BG Monitor BG Monitor - Diabetes Management

Changelog

See changelog here.

Credits

The following libraries are used:
CircularReveal - Adds circular reveal animation on Android versions < 5.0
ArcAnimator - Used to animate FAB in an arc

License

The MIT License (MIT)

Copyright (c) 2015 Gordon Wong

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.
Comments
  • Apk crashing below 5.0

    Apk crashing below 5.0

    App is crashing below 5.0 and when I include CircularReveal (as per the instructions), I am not able to build the apk only. I have raised issue with CircularReveal library also. Request you to please help me out in case if there is some workaround.

    link - https://github.com/ozodrukh/CircularReveal/issues/43

    invalid 
    opened by jiteshlalwani 16
  • FAB shift

    FAB shift

    FAB is shifted to the left after many clicks on it. Steps to reproduce in the sample 1.0.3:

    1. Click on FAB to open the sheet.
    2. Close the sheet using Back key or touching outside the sheet.
    3. Repeat steps 1 and 2 many times (maybe 20 or more).
    4. FAB is shifted to the left relatively of its initial position.
    bug 
    opened by alexeyr15 11
  • CardView radius style is not applied

    CardView radius style is not applied

    Hi, and thanks for this library. Unfortunately I am not able to style the cardview in the material sheet. For instance, attributes such as cardCornerRadius or cardBackgroundColor don't have any effect, nor in my app nor trying to modify the sample app. Trying to achieve this via code doesn't work either. Have you noticed the same behaviour?

    bug 
    opened by ticofab 9
  • FAB does not return the correct position on Android < 5.0

    FAB does not return the correct position on Android < 5.0

    Great lib, but... On Lollipop and higher all is going smooth and nice, on API 19 and lower fab going higher. Everything was made due to example. Stacked on it, help plz.

    bug 
    opened by dniHze 9
  • Sample App: Resource Not Found Exception

    Sample App: Resource Not Found Exception

    I keep getting this: FATAL EXCEPTION: main Process: com.gordonwong.materialsheetfab.sample, PID: 3563 android.content.res.Resources$NotFoundException: Resource ID #0x0 at android.content.res.Resources.getValue(Resources.java:1351) at android.content.res.Resources.getDrawable(Resources.java:804) at android.content.Context.getDrawable(Context.java:458) at android.support.v4.content.ContextCompatApi21.getDrawable(ContextCompatApi21.java:26) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:321) at android.support.v7.internal.widget.TintManager.getDrawable(TintManager.java:177) at android.support.v7.internal.widget.TintManager.getDrawable(TintManager.java:170) at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:53) at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:74) at com.gordonwong.materialsheetfab.sample.adapters.NotesAdapter.onBindViewHolder(NotesAdapter.java:52) at com.gordonwong.materialsheetfab.sample.adapters.NotesAdapter.onBindViewHolder(NotesAdapter.java:22) at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5212) at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5245) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4483) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4359) at android.support.v7.widget.LayoutState.next(LayoutState.java:86) at android.support.v7.widget.StaggeredGridLayoutManager.fill(StaggeredGridLayoutManager.java:1423) at android.support.v7.widget.StaggeredGridLayoutManager.onLayoutChildren(StaggeredGridLayoutManager.java:610) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2900) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1627) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1037) at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:747) at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42) at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1133) at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:760) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) at android.widget.LinearLayout.onLayout(LinearLayout.java:1495) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) at android.widget.LinearLayout.onLayout(LinearLayout.java:1495) at

    bug 
    opened by AndroidDeveloperLB 8
  • Issue: can't import

    Issue: can't import

    After trying to import and updating all things, I still get this error:

    Gradle 'material-sheet-fab' project refresh failed Error:No service of type Factory available in ProjectScopeServices.

    How come?

    opened by AndroidDeveloperLB 7
  • make sheet full screen

    make sheet full screen

    I want to make a full screen sheet. this is my layout file

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/eventdetail_coordinatorlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:context="com.hhtv.eventqa.activity.EventDetailActivity">
    
            <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/eventdetail_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:layout_scrollFlags="scroll|enterAlways"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
                <android.support.design.widget.TabLayout
                    android:id="@+id/eventdetail_tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fillViewport="false"
                    app:tabGravity="fill"
                    app:tabIndicatorColor="@color/base_color_4"
                    app:tabIndicatorHeight="@dimen/tablayout_indicator_height"
                    app:tabMode="fixed" />
            </android.support.design.widget.AppBarLayout>
    
            <android.support.v4.view.ViewPager
                android:id="@+id/eventdetail_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
    
        </android.support.design.widget.CoordinatorLayout>
        <com.hhtv.eventqa.customView.CustomFAB
            android:id="@+id/eventdetail_fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:layout_margin="@dimen/fab_margin"
            android:src="@drawable/ic_comment" />
    
        <com.gordonwong.materialsheetfab.DimOverlayFrameLayout
            android:id="@+id/dim_overlay"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
        <!-- Circular reveal container for the sheet -->
        <io.codetail.widget.RevealLinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <!-- Sheet that contains your items -->
            <android.support.v7.widget.CardView
                android:id="@+id/fab_sheet"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
    
            </android.support.v7.widget.CardView>
        </io.codetail.widget.RevealLinearLayout>
    </RelativeLayout>
    

    and the custom FAB class is same as your sample, but this is the result:

    http://i.imgur.com/Xd9toz6.gif

    please tell me how did I do wrong and how to fix it thanks

    question 
    opened by nienlm-hhtv 7
  • Problems after applying animation to Fab

    Problems after applying animation to Fab

    Hi

    I am applying an animation to the Fab to hide/show it when a list is scrolled. I apply the animation as so:

    fab.startAnimation(anim)

    The Fab animates correctly however when you tap the Fab after it has been animated the Fab does not transition into the material sheet correctly. Instead the Fab button grows in size and is drawn above the material sheet. Tapping it several more times makes it grow even larger until the app crashes with this exception:

    OpenGLRenderer: Error: Ambient Vertex Buffer overflow!!! used 480, total 320

    Is there a way to reinitialise the Fab after an animation has been applied to it?

    Thanks in advance.

    question 
    opened by phyora 6
  • Not working on S3

    Not working on S3

    On S3, when click on FAB, the sheet show at the top corner and just a small part visible. When click somewhere else on screen trying to cancel the sheet, FAB button stays hidden. I'm using the FAB implementation from your sample app.

    question 
    opened by Lesilva 6
  • Fab is not shown after sheet is closed

    Fab is not shown after sheet is closed

    I want to leave the sheet open after the device rotation, so if the sheet was open, then I manually call showSheet(). Sheet is shown as expected, but when I close it by pressing back key, the sheet is closed, but the fab does not appear. If I don't call showSheet(), the fab shows and works as usual.

    Is this a bug or do I have to call something else for the fab to show after closing the sheet?

    opened by TadejZupancic 4
  • Memory Leak in MaterialSheetFab

    Memory Leak in MaterialSheetFab

    The call:

    // Set listener for when FAB view is laid out
            fab.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                        @Override
                        public void onGlobalLayout() {
                            // Initialize FAB anchor when the FAB view is laid out
                            if (!isFabLaidOut) {
                                updateFabAnchor();
                                isFabLaidOut = true;
                            }
                        }
                    });
    

    appears to leak the instance to this sheet (causing my activity to leak), since it's not removed from the OnGlobalLayoutListener. This was caught using LeakCanary.

    bug 
    opened by agrosner 4
  •  Animators may only be run on Looper threads

    Animators may only be run on Looper threads

    when hide sheet hideSheet(); get error: FATAL EXCEPTION: cs-decoder Process: com.example.cexup_device, PID: 9091 android.util.AndroidRuntimeException: Animators may only be run on Looper threads at android.animation.ValueAnimator.start(ValueAnimator.java:1044)

    opened by triandamai 0
  • How to set different background resource in fab button

    How to set different background resource in fab button

    Right now I'm only able to set rounded button which is the default and I want to switch to the rounded rectangle with some left drawable and some text in right. Thanks for the amazing library.

    opened by Shubham-vish 0
  • Error: Program type already present: io.codetail.widget.RevealLinearLayout

    Error: Program type already present: io.codetail.widget.RevealLinearLayout

    When I add material sheet fab dependency 'com.gordonwong:material-sheet-fab:1.2.1' i can't build my project. Build fails with this message:

    Error: Program type already present: io.codetail.widget.RevealLinearLayout

    I've also tried inserting dependency in this way, without success:

    implementation 'com.gordonwong:material-sheet-fab:1.2.1', { exclude group: 'io.codetail.widget', module: 'RevealLinearLayout' }

    opened by ffdez 0
  • FAB allows scrolling when in sheet mode, which then breaks layout when minimized

    FAB allows scrolling when in sheet mode, which then breaks layout when minimized

    When I click the FAB, it morphs into the sheet. I can click somewhere in the sheet, hold, and drag down to begin scrolling my CoordinatorLayout/NestedScrollView in the background. If I do any such sort of scrolling, when I dismiss the sheet, the FAB is put in a buggy location with a buggy size.

    opened by ghost 0
Owner
Gordon Wong
Gordon Wong
A simple Floating Action Button that shows an anchored Navigation View

Floating Navigation View A simple Floating Action Button that shows an anchored Navigation View and was inspired by Menu Material Fixed created by Tom

André Mion 1.3k Dec 29, 2022
A dual-function menu button that offers a default action as well as the possibility of choosing a different action by selecting from a set of alternatives.

A dual-function menu button that offers a default action as well as the possibility of choosing a different action by selecting from a set of alternatives.

Kojo Fosu Bempa Edue 114 Nov 29, 2022
🚀 A very customizable library that allows you to present menu items (from menu resource and/or other sources) to users as a bottom sheet.

SlidingUpMenu A library that allows you to present menu items (from menu resource and/or other sources) to users as a bottom sheet. Gradle Dependency

Rasheed Sulayman 26 Jul 17, 2022
Spinner with bottom sheet dialog for Android

This is a small library for spinner view with displaying options in bottom sheet dialog. This view doesn't improve or extend the default android Spinner. The library doesn't support any other types of showing menu, only bottom sheet dialog.

Oleg Nestyuk 23 Oct 19, 2022
Kai Liao 2.2k Jan 3, 2023
You can create awesome menus with bottom sheet experience in a few lines

You can create awesome menus with bottom sheet experience in a few lines

Mazen Rashed 19 Nov 1, 2022
Bottom Sheet fragment with a sticky header and a content recycler view

Sticky Header Bottom Sheet A simple library to create a Bottom Sheet with a sticky header and a content recycler view. The bottom sheet expands on scr

Kshitij Kumar 12 Sep 21, 2022
Bottom Navigation widget component inspired by the Google Material Design Guidelines at https://www.google.com/design/spec/components/bottom-navigation.html

Material Bottom Navigation Library Lightweight Bottom Navigation library component inspired by the Google Material Design Guidelines at https://www.go

Alessandro Crugnola 1.4k Dec 18, 2022
A floating menu library for Android.

Hover Hover is a floating menu implementation for Android. Goals The goals of Hover are to: Provide an easy-to-use, out-of-the-box floating menu imple

Google 2.7k Dec 27, 2022
A menu consisting of icons (ImageViews) and metaball bouncing selection to give a blob effect. Inspired by Material design

Metaball-Menu A menu consisting of icons (ImageViews) and metaball bouncing selection to give a blob effect. Inspired by Material design ScreenShot Us

AbYsMeL 198 Sep 15, 2022
Neat library, that provides a simple way to implement guillotine-styled animation

Guillotine animation Neat library, that provides a simple way to implement guillotine-styled animation Check this [project on Dribbble] (https://dribb

Yalantis 2.7k Jan 3, 2023
Spotify like android material bottom navigation bar library.

SuperBottomBar About Spotify like android material bottom navigation bar library. GIF Design Credits All design and inspiration credits belongs to Spo

Ertugrul 73 Dec 10, 2022
:fire: The powerful and easiest way to implement modern material popup menu.

PowerMenu ?? The powerful and easiest way to implement modern material popup menu. PowerMenu can be fully customized and used for popup dialogs. Downl

Jaewoong Eum 1k Dec 29, 2022
An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Jeremy Feinstein 11.1k Dec 21, 2022
Android-NewPopupMenu 3.9 0.0 Java is an android library to create popup menu with GoogleMusic app-like style.

Android-NewPopupMenu Android-NewPopupMenu is an android library to create popup menu with GoogleMusic app-like style. Requirements Tested with APIv4 H

u1aryz 159 Nov 21, 2022
BottomSheet-Android - A simple customizable BottomSheet Library for Android Kotlin

BottomSheet-Android A simple customizable BottomSheet Library for Android Kotlin

Munachimso Ugorji 0 Jan 3, 2022
Simple library which enable you to add a drawer(slide-out) navigation to your android application

SimpleSideDrawer is an android library to add a drawer navigation into your android application. This library has high affinity with other libraries l

null 217 Nov 25, 2022
Android Library for a DrawerLayout similar to the one in Google Apps

GoogleNavigationDrawerMenu This project aims to let you use a ListView menu similar to the one in the new Google Apps (Keep, Play Music...) without ha

Jorge Martin Espinosa 267 Nov 25, 2022