I am trying to change color of my snackbar
snackbarView.setBackgroundColor(ContextCompat.getColor(context, Color.RED));
I am getting something like this :
android.content.res.Resources$NotFoundException: Resource ID #0xffff0000
Where definitely
0xffff0000
represents RED.But why it cant find this resource? Any help?
use: snackbarView.setBackgroundColor(Color.RED);
not: snackbarView.setBackgroundColor(ContextCompat.getColor(context, Color.RED));
Reason:
Look at the official android developer site.

So, you can directly add a color to it. No need to add ContextCompat.getColor() method to it.
If you want to use this, please use a valid resource id, not color id as the second parameter of the getColor method. Because from official website it says,

it needs resource id, not color id. Hope, now, you can understand this matter.
Try this :-
In your values.xml , create colors.xml and add following line :
<color name="red">#FF0000</color>
Then call this color like this :-
snackbarView.setBackgroundColor(ContextCompat.getColor(context,R.color.red));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With