Adding a FloatingActionButton FAB

suggest change

In Material Design, a floating action button represents the primary action in an activity.

It is a circled icon floating above the UI, with motion that can include morphing, launching, and transferring its anchor point.

Make sure the following dependency is added to your app’s build.gradle file under dependencies:

compile 'com.android.support:design:25.3.1'

Now add the FloatingActionButton to your layout file:

<android.support.design.widget.FloatingActionButton
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_margin="16dp"
      android:src="@drawable/some_icon"/>

where the src attribute references the icon that should be used for the floating action.

The result should look something like this (presuming your accent color is Material Pink):

By default, the background color of your FloatingActionButton will be set to your theme’s accent color. Also, note that a FloatingActionButton requires a margin around it to work properly. The recommended margin for the bottom is 16dp for phones and 24dp for tablets.

These attributes customize the FloatingActionButton further. Declare xmlns:app="http://schemas.android.com/apk/res-auto" on the root element of the layout:

You can find more examples about FAB here.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents