简体   繁体   中英

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!". 我看不到“UNDO”文字

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM