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.

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


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

Create a new Drawable Resource

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

Adding FAB in XML Layout

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

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

Post a Comment

Powered by Blogger.