Resources.getColor(int id)
方法已被弃用。
@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException {
return getColor(id, null);
}
我该怎么办?
最佳答案
从 Android 支持库 23 开始,
一个新的getColor()方法已添加到 ContextCompat
。
来自官方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.
所以,只需调用:
ContextCompat.getColor(context, R.color.your_color);
您可以检查 ContextCompat.getColor()
source code on GitHub .
关于android - 在 Android 6.0 Marshmallow (API 23) 上不推荐使用 getColor(int id),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31590714/