简体   繁体   中英

Snackbar does not show text

I'm using Google Design library (23.1.0) to show snackbars. My snackbar code lookls like:

Snackbar snackbar = Snackbar.make(getView(), "Deleted", Snackbar.LENGTH_LONG);
snackbar.setActionTextColor(getResources().getColor(R.color.accent_color));
snackbar.setAction(R.string.undo, //anonymous class omitted);
snackbar.setCallback(//anonymous class omitted);
snackbar.show();

The snackbar is being created and shown. Action label, action color, and all listeners works as expected. The only thing is that the message "Deleted" is not being shown. If I use debugger and stop execution on: snackbar.show(), I can see that inside snackbar > mView > mMessageView there is a field called mText and it has value of "Deleted". Yet I cannot see the message on the snackbar. I have tried already using both string consts and resources id.

Whats more, I have tried using very similar code in clean project and it works. What might be the cause?

缺少文字

Oh, it looks like the text color was really the same as background. I've replaced:

Snackbar snackbar = Snackbar.make(getView(), "Deleted", Snackbar.LENGTH_LONG);

With:

Snackbar snackbar = Snackbar.make(fab, Html.fromHtml("<font color=\"#ffffff\">Deleted</font>"), Snackbar.LENGTH_LONG);

And now I can see the text.

After a little futher investigation the default color for snackbar text is taken from theme.xml. I case of our project the value of textColor was set to #313131 and the background of snackbar is #323232. Impossible to notice.

Maybe something is wrong with the color of text (R.color.accent_color). Maybe text color as background color?

Try without this option:

Snackbar snackbar = Snackbar.make(getView(), "Deleted", Snackbar.LENGTH_LONG);
snackbar.setAction(R.string.undo, //anonymous class omitted);
snackbar.setCallback(//anonymous class omitted);
snackbar.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