Create a Floating Action Button

Introduction
This tutorial follows the tutorial Create a Toolbar, which teaches how to implement a Toolbar by creating a CoordinatorLayout. You will need the CoordinatorLayout to insert a Floating Action Button. If your layout doesn't have one, follow the Create a Toolbar tutorial.

Create the Floating Action Button
In your CoordinatorLayout, insert a Floating Action Button after your activity content. Set the android:src to the icon you want to be displayed. You can use the standard icons by typing @android:drawable/, or you can download or create new ones by yourself. Set the gravity to the position you want the FAB to be displayed.

Your layout should look like this:

Importing
Import the following classes:

View is used to handle the click in the Floating Action Button and the FloatingActionButton is the base class for itself.

Override the onCreate method
Get the FAB by using the findViewById method. Then setup a click listener to perform the desired function when clicked.

When you finish, your Java Class file should look like this:

Conclusion
Your activity should now have a working Floating Action Button. For the next steps, you should play along with the CoordinatorLayout and the gravity of the FAB to place it in other positions, such as between the toolbar and the content layout, and so on.

You now know how to create a Floating Action Button and how to place it on your Activity.