I'm trying to create snackbar with custom layout. Give me an example if it is possible.
Asked
Active
Viewed 1.4k times
3 Answers
2
Custom layouts are discouraged due to the intended use of Snackbars, they're essentially "interactive toasts" and shouldn't contain anything more than a message and an action.See the design guidelines for more information.

Muhammad Waleed
- 2,517
- 4
- 27
- 75
0
Just try with this
Snackbar snackbar = Snackbar
.make(coordinatorLayout, "This is snackbar", Snackbar.LENGTH_LONG);
snackbar.show();
Or else
Snackbar snackbar = Snackbar
.make(coordinatorLayout, "Message is deleted", Snackbar.LENGTH_LONG)
.setAction("UNDO", new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar snackbar1 = Snackbar.make(coordinatorLayout, "Message is restored!", Snackbar.LENGTH_SHORT);
snackbar1.show();
}
});
snackbar.show();

Aditya Vyas-Lakhan
- 13,409
- 16
- 61
- 96
0
final SnackBar mSnackBar = SnackBar.make(getActivity()).
applyStyle(getResources().getColor(R.color.colorPrimaryDark));
mSnackBar.text("This is SnackBar")
.singleLine(true)
.textSize(15)
.textColor(getResources().getColor(R.color.colorAccent))
.actionText("CLOSE")
.actionTextColor(getResources().getColor(R.color.colorPrimary))
.actionClickListener(new SnackBar.OnActionClickListener() {
@Override
public void onActionClick(SnackBar sb, int actionId) {
// Handle click
}
})
.duration(5000);

JJD
- 50,076
- 60
- 203
- 339

Pavan Bilagi
- 1,618
- 1
- 18
- 23