0

From these answers, I suppose I know how to grab the primary color. However, when I try to set the background color of the toolbar, I keep getting exception that the resourceId for the color I am specifying is not found

android.content.res.Resources$NotFoundException: Resource ID ...

I have tried

toolbar.setBackgroundResource(primaryColor);

and I have tried

toolbar.setBackgroundColor(primaryColor);
Community
  • 1
  • 1
Nouvel Travay
  • 6,292
  • 13
  • 40
  • 65

1 Answers1

0

I think that in your case, you are passing the resource id of the color as the argument to the setBackgroundColor method. You want to pass the integer that the color actually evaluates to instead. There are a number of ways to do this depending on what information you have (hex string, rgb integer values, etc. Check out the docs for more info on defining a color value.

Assuming that your color is defined in colors.xml in your res/values folder, you should be able to simply use this:

toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.primaryColor);

Otherwise, you'll have to define your color programmatically first as I mentioned.

AndroidDev
  • 20,466
  • 42
  • 148
  • 239