Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

android - Snackbar action text color not changing

I want to change the action text color for my snackbar, but it is not working for some reason.

I use the following code to display a snackbar:

Snackbar.make(findViewById(R.id.root), "text", Snackbar.LENGTH_LONG).setActionTextColor(R.color.yellow).setAction("OK", new View.OnClickListener() {
    @Override
    public void onClick(View view) {
    }
}).show();
question from:https://stackoverflow.com/questions/31116774/snackbar-action-text-color-not-changing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The argument of setActionTextColor is the int that represents the color, not the resource ID.

Instead of this:

.setActionTextColor(R.color.yellow)

try:

.setActionTextColor(Color.YELLOW)

If you want to use resources anyway, try:

.setActionTextColor(ContextCompat.getColor(context, R.color.color_name));

Note: To use ContextCompat, I assume you have included Support library to your build.gradle file (It is optional if you have already appcompat (v7) library too).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...