I created a small toy to demo Android snackbar featrue, you can find the project on cwliu/Try_Snackbar
Setup
In app build.gradle, add design support library:
dependencies {
...
compile 'com.android.support:design:22.2.0'
}
Show snackbar
Just like the toast usage,
Snackbar.make(view, "Hello world",Snackbar.LENGTH_LONG).show();
Set snackbar action
snackbar.setAction("Undo", new View.OnClickListener() {
@Override
public void onClick(View v) {
// Do something
}
});
Integrate snackbar to floating action button
coordinator_layout = findViewById(R.id.coordinatorlayout);
Snackbar.make(coordinator_layout, "Hi", Snackbar.LENGTH_LONG).show();
Customize snackbar styling
In stylings.xml,
<style name="Widget.Design.Snackbar" parent="android:Widget …