4

I solved it like this, do you think it is correct?

getColor(int id, Theme theme);
getColor(R.color.green, getContext().getTheme());

Where "green" is in res/colors.xml:

color name="green">#FF00FF00</color>
Alireza Akbari
  • 2,153
  • 2
  • 28
  • 53
marioc
  • 41
  • 1
  • 3

1 Answers1

6

Use ContextCompat.getColor(context, R.color.color_name) As this answer shows: getResources().getColor() is deprecated

FalcoVerhagen
  • 154
  • 1
  • 8