Skip to content

Most visited

Recently visited


Add a Floating Action Button

A floating action button (FAB) is a circular button that triggers the primary action in your app's UI. This page shows you how to add the FAB to your layout, customize some of its appearance, and respond to button taps.

To learn more about how to design a floating action button into your app according to the Material Design Guidelines, also see Buttons: Floating Action Button.

Figure 1. A floating action button

Add the floating action button to your layout

The following code shows how the FloatingActionButton should appear in your layout file:

        android:layout_margin="16dp" />

By default, the FAB is colored by the colorAccent attribute, which you can customize with the theme's color palette.

You can configure other FAB properties using either XML attributes or corresponding methods, such as the following:

Respond to button taps

You can then apply an View.OnClickListener to handle FAB taps. For example, the following code displays a Snackbar when the user taps the FAB:

FloatingActionButton fab = findViewById(;
fab.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();

For more information on the capabilities of the FAB, see the API reference for the FloatingActionButton.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)