In this post we will talk about Floating Action Button.

Floating action buttons are used for a promoted action. They are distinguished by a circled icon floating above the UI and have motion behaviors that include morphing, launching, and a transferring anchor point.

Floating action buttons come in two sizes:

  • Default size: For most use cases
  • Mini size: Only used to create visual continuity with other screen elements

different size of fab
For change size of button need to use fabSize attribute with value: mini or normal.

Firstly need to add library or add dependency for gradle.
[xml]
dependencies {
compile ‘com.android.support:design:22.2.0’
}
[/xml]

Next step is adding floating action button to layout.
[xml]


[/xml]

After it need to update Activity.
[java]
public class FABActivity extends ActionBarActivity implements View.OnClickListener {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fab_layout);

((FloatingActionButton)findViewById(R.id.fab)).setOnClickListener(this);
}

@Override
public void onClick(View v) {
Snackbar.make(findViewById(R.id.main_content), “TEST”, Snackbar.LENGTH_SHORT).show();
}
}
[/java]

Unfortunately Snackbar lock floating action button.

snackbar locked fab

For fix this problem need to use CoordinatorLayout.
[xml]




[/xml]

After it all works correctly.
fab_correct

1 CommentClose Comments

Leave a comment

Newsletter Subscribe

Get the Latest Posts & Articles in Your Email

We Promise Not to Send Spam:)