Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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(); 
like image 523
qwertz Avatar asked Jun 29 '15 13:06

qwertz


2 Answers

Use

.setActionTextColor(getResources().getColor(R.color.red)) 

instead of just

.setActionTextColor(R.color.red) 
like image 29
Adam Purser Avatar answered Sep 19 '22 21:09

Adam Purser


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).

like image 76
Anand Singh Avatar answered Sep 19 '22 21:09

Anand Singh