3

How do I get the Snackbar to show the "UNDO" or "RETRY" text on the right hand side?

I've tried setActionTextColor() but it has no effect.

MyFragment.java

Snackbar.make(getView(), "Profile saved!", Snackbar.LENGTH_LONG)
    .setAction(R.string.snackbar_action_undo, null)
    .setActionTextColor(ContextCompat.getColor(getActivity(), R.color.ColorBrightAccent))
    .show();

I've also tried

Snackbar.make(getView(), "Profile saved!", Snackbar.LENGTH_LONG)
    .setAction(R.string.snackbar_action_undo, null)
    .setActionTextColor(Color.YELLOW)
    .show();

strings.xml

<string name="snackbar_action_undo">UNDO</string>

There is no "UNDO" beside "Profile saved!". I can't see the "UNDO" text

I've looked at the solution here, but it seems to apply to the text on the left-hand side.

Any help would be appreciated.

Community
  • 1
  • 1
VIN
  • 6,385
  • 7
  • 38
  • 77

1 Answers1

11

Maybe try to add a action with a OnClickListener

Snackbar snackbar = Snackbar.make(v, "Profile saved!", Snackbar.LENGTH_INDEFINITE)
                    .setAction("UNDO", new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Log.e("TAG", "Done");
                        }
                    }).show();
rib
  • 190
  • 1
  • 11