Killiam Killiam - 6 months ago 40
Android Question

Snackbar not showing action text

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.

rib rib
Answer

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();