Remove Floating Action Button from the Blank Activity — January 31, 2016

Remove Floating Action Button from the Blank Activity

From the beginning of its days, Android has been changing a lot in its concepts.

In the recent time, one of the changes brought by the Material Design is the Floating Action Button. These can only be used with API 21 and above. But the appcompat support library v7 makes most of the Material Design supportable with the APIs before API 21.

1

In the Android Studio, whenever I opt for a Blank Activity, this Floating Action Button also displays in the layout.

The Floating Action button can be removed from the app, if one does not want to use it. After all, this widget is also a part of Layout only.

To remove this widget, Remove the following code from the activity_main.xml 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:layout_margin="@dimen/fab_margin"  
 android:src="@android:drawable/ic_dialog_email" />  

 

Also delete the unnecessary code from the MainActivity.java

 FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);  
 fab.setOnClickListener(new View.OnClickListener() {  
   @Override  
   public void onClick(View view) {  
     Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)  
         .setAction("Action", null).show();  
   }  
 });  

 

Now you are good to go without the Floating Action Button. 🙂