Issue
Using:
buildToolsVersion "22.0.1"
,
targetSdkVersion 22
in my gradle file.
I found that the useful getResources().getColor(R.color.color_name)
is deprecated.
What should I use instead?
Solution
It looks like the best approach is to use:
ContextCompat.getColor(context, R.color.color_name)
eg:
yourView.setBackgroundColor(ContextCompat.getColor(applicationContext,
R.color.colorAccent))
This will choose the Marshmallow two parameter method or the pre-Marshmallow method appropriately.
Answered By - Barry Irvine
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.