-2

I'm trying to create snackbar with custom layout. Give me an example if it is possible.

Arvin Jayanake
  • 1,345
  • 3
  • 13
  • 26

3 Answers3

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,523
  • 2
  • 26
  • 72
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,007
  • 15
  • 58
  • 92
0

Refer This Link

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
  • 47,369
  • 53
  • 194
  • 328
Pavan Bilagi
  • 1,528
  • 1
  • 16
  • 22