Adding a FloatingActionButton FAB
suggest changeIn 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:
app:fabSize: Can be set tonormalorminito switch between a normal sized or a smaller version.app:rippleColor: Sets the color of the ripple effect of yourFloatingActionButton. Can be a color resource or hex string.app:elevation: Resting elevation, as a dimension such as6dp.app:useCompatPadding: Boolean. Set it totrueon API 21 and later so the padding matches older API levels.
You can find more examples about FAB here.