Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Snackbar in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 505
    Comment on it

    Basically snackbar use to show message like a Toast but here the advantage is we have event to interact in it.

    It shows message on the bottom of the screen. And it will remove when we swipe off.
    First of all add this in your gradle file

    dependencies { 
        compile fileTree(dir: 'libs', include: ['*.jar']) 
        compile 'com.android.support:appcompat-v7:23.0.1' 
        compile 'com.android.support:design:23.0.1' 
    } 

    We make CoordinatorLayout to our xmls parent because when we swipe off we need to remove the message.

    Below is the example of simplest Snackbar.

    Snackbar snackbarExample  = Snackbar .make(coordinatorLayout, "Got 
    Snackbar",Snackbar.LENGTH_LONG); 
     snackbarExample.show(); 

    Now Another example of snackbar with callbacks

    Snackbar snackbarExample = Snackbar.make(coordinatorLayout, "Page is removed.", 
    Snackbar.LENGTH_LONG) .setAction("UNDO", new View.OnClickListener() { 
                @Override 
                public void onClick(View view) { 
                    Snackbar snackbarEx = Snackbar.make(coordinatorLayout, "Page is loaded.", 
    Snackbar.LENGTH_SHORT); 
                    snackbarEx.show(); 
                } 
            }); 
     snackbarExample.show(); 

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: