【发布时间】:2023-03-31 01:46:01
【问题描述】:
Resources.getColor(int id) 方法已被弃用。
@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException {
return getColor(id, null);
}
我该怎么办?
【问题讨论】:
-
使用 ContextCompat.getColor(context, R.color.color_name)
-
用上面提到的这个方法:getColor(context, R.color.your_color);目前尚不清楚如何获得“上下文”。仅在我的情况下,android studio 3.2 中将上下文放在那里是行不通的。我发现这对我有用。 .setTextColor(Color.RED).
标签: android android-resources android-6.0-marshmallow android-mnc