I had the same problem, I think, and resolved it by adding the @SuppressWarnings("ResourceAsColor") annotation on top of the method.
The reason is that, in my opinion, Lint does not recognize the new API at the moment, although it is valid. Both methods return an integer that represents the allowed color. In my tests, Resources.GetColor () and ContextCompat.GetColor () return the same value. However, when using the latter, I get an error message in Android Studio:
Should pass resolved color instead of resource id here: `getResources().getColor(titleColor)`
... which does not make sense because I am missing the allowed color. This is just int , since I could be wrong ... Therefore, in conclusion, I believe that suppressing Lint Error is a valid way to handle the situation at the moment.
If you do not agree, please raise your voice, I would be interested.
Stan
source share