Saturday, 19 March 2016

Android Floating Action Button(FAB) With SnackBar Material Design : How To create a FAB with Snack bar using Android Studio

Floating Action Button With SnackBar
Material Design



Note: In this Category  Android studio make default view with Floating Action Button and Snack bar, If you create a new Project click any activity with including FAB.

"Create a new Project and next blank activity
you will see the FAB with snackbar"

1.Add your support  file on "build.gradle" inside your app folder

compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'

Add inside into dependencies {  .........   }
if your gradle version is 23.2.0.. may be its changed by your project.. replace version number to <your version number>



2. This is a xml file to placing your layout file

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:src="@drawable/ic_launcher"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"  />


Add inside into <your Layout File> Example: activity_main.xml




3.Java file code <update coding to your Java File>

FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
   @Override   public void onClick(View view) {

         Snackbar.make(view, "Replace your Own Action", Snackbar.LENGTH_LONG)
               .setAction("Action", null).show();
 
} });



Floating Action Button With SnackBar
Material Design



No comments:

Post a Comment