Understanding the purpose of this code in the onCreate() method

0 Pranav Thombre · January 26, 2016
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
This is an additional bit of code that is present in the onCreate method. This does not appear in the android app dev tutorials that i am currently watching. What is the purpose of this bit of code. How does it effect the interface?

Post a Reply


Oldest  Newest  Rating
0 Pranav Thombre · January 29, 2016
Thank you!
0 Gary Whitney · January 27, 2016
 I would say go to http://developer.android.com/reference/android/support/design/widget/Snackbar.html
but that won't directly answer your question.
When you look at the layout in design view you will see the  circle with an edit icon floating above the layout.
(You may even have seen this on your phone if apps like email and messages have updated to Marshmallow i.e. V23.)

This is included in the Blank Activity for V23, which also favors tool bars over action bars.
If you want to follow the tutorials try this:
* Create an Empty Activity.
* Don't change the type of activity i.e. leave AppCompat
* See that little droid icon with 23 next to it. Change it to 21. That is what was used at the time the tutorials were created.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator