Read complete story

How to make customizable Snackbar in android

In this blog,

We ‘ll discuss the UX concept which is introduced in Android 5.0 material design called Snackbar. Which is inspired from the Toast widget of android.

You can call it as a toast message with an action button. SnackBar will be displayed at the bottom or bottom left for a larger device It can be swiped off in order to dismiss them if passing CoordinatorLayout as view param of SnackBar.

How to make simple Snackbar

Below is the syntax of a simple snackbar.

The make function accepts three parameters. View, display message and duration of the message to be displayed.

View: Find a parent view to hold Snackbar’s view from the value given to view(in this case our coordinatorLayout).

The duration should be LENGTH_SHORT, LENGTH_LONG or LENGTH_INDEFINITE. When LENGTH_INDEFINITE is used, the snackbar will be displayed indefinite time and can be dismissed with swipe off.

And you can set the duration of your snackbar by setDuration(int) method.

 

How to make Snackbar with Action Callback

We can also set a callback interaction method using setAction() method.

In above example, There is a snackbar with retry action callback method.

How to make our custom Snackbar

Snackbar’s default text color is white and in android 5.0 or above it takes the primary color automaticlly. And #323232 background color. But we can customize that things.

In above example, We set the actionbar color to GREEN and text color to BLUE.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close