Reputation:
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 :)
Upvotes: 2
Views: 520
Reputation: 22965
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)
color.xml
<color name="colorAccent">#607d8b</color>
Upvotes: 0
Reputation: 6855
Set the custom color using the below line
snackbar.setActionTextColor(Color.parseColor("#a1b2c3"));
This will resolve your issue.
Upvotes: 3