Cody Blog

How to use Android Snackbar

I created a small toy to demo Android snackbar featrue, you can find the project on cwliu/Try_Snackbar

snackbar demo


In app build.gradle, add design support library:

dependencies {
    compile ''

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() {
    public void onClick(View v) {
       // Do something

Integrate snackbar to floating action button

coordinator_layout = findViewById(;
Snackbar.make(coordinator_layout, "Hi", Snackbar.LENGTH_LONG).show();

Customize snackbar styling

In stylings.xml,

<style name="Widget.Design.Snackbar" parent="android:Widget">
    <item name="android:background">#00FF00</item>

For more styling options, couldrefer to /build/intermediates/exploded-aar/



Related Posts