Floating Action Button (FAB) Code Snippet for Android Studio
July 7, 2019
Welcome. In this tutorial you will learn how to add a Floating Action Button in your Android Devices.
Android Floating Action Button (FAB) Example
Floating Action Button (also known as FAB) is a special type of button in Android that is generally circular and is displayed at the bottom as a small round button. They are used to trigger special type of action in your app’s UI. In this page you will learn how to add a Floating action button to your android’s UI and also how to perform an operation when the button is tapped.
Inserting the Floating Action Button in your layout
To create a floating action button, just add these lines of code to your XML file:-
Snackbar.make(view,"Floating action button is working",Snackbar.LENGTH_LONG)
The above code will create a floating action button and once the user clicks on it, it will display a snackbar on the bottom of the page. You can even add your desired code inside the onClick function.
The image below shows a pink colored floating action button which is placed at the bottom.
Once the button is pressed, it will display a snackbar at the bottom like this:-
The Complete Code Snippet for above example is given below:-