Search code examples
javaandroidandroid-5.0-lollipopmaterial-designandroid-design-library

Android L - Floating Action Button (FAB)


Did Google already released a defined style or a component for this new circular FAB button or should I implement the design on my own?

The button is described here: Google Design | Floating Action Buttons

EDIT (05/2015): Check Lukas' answer / Gabriele's answer showing an easy way to implement it with the design support library.


Solution

  • UPDATE: there's now an official widget for FAB: FloatingActionButton, see Gabriele Mariotti reply for full information.

    According to Adam Powell and Chet Haase they didn't create a widget for the FAB button cause it's a very easy component to reproduce.

    There was a question in the Google IO 2014 speech "Google I/O 2014 - Material science: Developing Android applications with material design", at the end of the speech (at about 37:50) there was exactly that question, you can hear it here: https://www.youtube.com/watch?v=lSH9aKXjgt8#t=2280

    Chet Haase says there's a RoundedBitmapDrawable (I didn't check if that's the name) that should already do the job of defining the Outline.

    But you can do it with your own drawable, set an Elevation to it and define an circle Outline programmatically.

    This should give you the round button with shadow on L release. But I think You'll have to build the Shadow pre-L on your own.

    I should check the code for CardView to see how it reproduce the shadow pre-L. I'll probably do that, but do not have time now. If no one pops in with the details I'll do it after I've found the time to go and check it up.

    EDIT:

    Gabriele Mariotti (see his answer below, thank you) added some code to show you how to do it.

    Thanks to @shomeser comments, he wrote a library to make the fab button:

    https://github.com/shamanland/floating-action-button

    To use it:

    dependencies {
        compile 'com.shamanland:fab:0.0.3'
    }
    

    You can also read his answer to another question: How can I add the new "Floating Action Button" between two widgets/layouts