getResources().getColor() is deprecated

The Solution to getResources().getColor() is deprecated is


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 on 2015-08-25 11:00:03


Most Viewed Questions: