2

I need to change the colour of the action button in Snackbar with a colour that is not pre-defined by Android studio (ie. without using Color.BLUE, etc).

I have researched on this question in Google/stack overflow. But so far all the tutorials out there only uses default values. But I would like to use hex values (eg. #a1b2c3)

Thus, I would like to know if this is possible. Thanks in advance :)

gauravsheohar
  • 396
  • 5
  • 12

2 Answers2

3

Set the custom color using the below line

 snackbar.setActionTextColor(Color.parseColor("#a1b2c3"));

This will resolve your issue.

Maheshwar Ligade
  • 6,709
  • 4
  • 42
  • 59
0

Use this code,

snackBar.setActionTextColor(getResources().getColor(R.color.colorAccent));

getResources().getColor(R.color.colorAccent) is deprecated by android you have to use the ContextCompat

ContextCompat.getColor(context, R.color.my_color)

Check this stack answer

color.xml

<color name="colorAccent">#607d8b</color>
Community
  • 1
  • 1
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142