WepsTech
The world of development
The world of development
Another interesting component introduced in Material Design is the Snackbar. Snackbars are just like Toast messages except they provide action to interact with. Snackbar will be displayed at the bottom of the screen and can be swiped off in order to dismiss them.
This article explains about snackbar with few examples covering different scenarios.
Snackbar snackbar = Snackbar.make(this.findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG);
snackbar.show();
Snackbar.make(parentlayout, "This is main activity", Snackbar.LENGTH_LONG)
.setAction("CLOSE", new View.OnClickListener() {
@Override
public void onClick(View view) {
//Action
}
})
.setActionTextColor(getResources().getColor(android.R.color.holo_red_light ))
.show();
Snackbar snack = Snackbar.make( (((Activity)context).findViewById(android.R.id.content)),message + "", Snackbar.LENGTH_SHORT);
snack.setDuration(Snackbar.LENGTH_INDEFINITE);//change Duration as you need
View view = snack.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);//change textColor
TextView tvAction = (TextView) view.findViewById(android.support.design.R.id.snackbar_action);
tvAction.setTextSize(16);
tvAction.setTextColor(Color.WHITE);
snack.show();