Loading...

Floating Action Button (FAB) Using Android Design Support Library

In this example, you will learn to implement the android Floating Action Button (FAB) in android application using design support library. Floating Action Buttons (FAB) are used for a promoted action. Android floating action buttons (FAB) come in different two sizes, default and mini size. Default size of FAB is used for most of the cases and mini size is only used to create virtual continuity with other screen elements. Implementing FAB in app using design support library is not so difficult.

Related:
Floating Action Buttons: Awesome Material Design Android FAB Libraries
Android Material Design ActionBar/App Bar: How to Make Custom ActionBar
Android WebView Tutorial with Example

Create a new Android Project


Let’s start by creating a new android project to implement Floating Action Button in android application using design support library with following information.
Application Name: Android Floating Action Button
Company Domain: viralandroid.com
Package Name: com.viralandroid.androidfloatingactionbutton
Minimum SDK: Android 2.2 (API 8 Froyo)

Add Design Support Library Dependency


Add following design and appcompat support library dependency in your build.gradle file which looks like this.

Modify styles.xml File

res/values/styles.xml

Now, create a colors.xml file in your values directory and add following code.
res/values/colors.xml

Create a new Drawable Resource


Create a fab_plus.xml file in your project drawable resource directory and add following code.
res/drawable/fab_plus.xml

Adding FAB in XML Layout


Add floating action button (fab) in your xml layout file. Following is the final code of xml layout file.
res/layout/android_fab.xml

Following is the default code of MainActivity.xml file.

And following is the default strings.xml file.

Now, run your application which looks like this.

Floating Action Button (FAB) Using Android Design Support Library
Android FAB Using Design Support Library

XML 5980256877688420771
Home item