Starting from Android Support Library 23,
a new getColor() method has been added to ContextCompat
.
Its description from the official JavaDoc:
Returns a color associated with a particular resource ID
Starting in M, the returned color will be styled for the specified Context's theme.
So, just call:
ContextCompat.getColor(context, R.color.your_color);
You can check the ContextCompat.getColor()
source code on GitHub.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…