In this post we will talk about Snackbar.

Snackbars provide lightweight feedback about an operation by showing a brief message at the bottom of the screen. Snackbars can contain an action.

Firstly need to add library or add dependency for gradle.
[xml]
dependencies {
compile ‘com.android.support:design:22.2.0’
}
[/xml]
You can use Snackbar without Action:
[java]
Snackbar.make(findViewById(R.id.root), “Click”, Snackbar.LENGTH_SHORT).show();
[/java]
Snackbar without action
If you want add to action to Snackbar you must use setAction function:
[java]
Snackbar.make(findViewById(R.id.root), “Click”, Snackbar.LENGTH_SHORT).setAction(“UNDO”,
new View.OnClickListener() {
@Override
public void onClick(View v) {
//some action
}
}).show();
[/java]
Snackbar with action
Layout file for this project
[xml]

1 CommentClose Comments

Leave a comment

Newsletter Subscribe

Get the Latest Posts & Articles in Your Email

We Promise Not to Send Spam:)