解决方式
将 getColor()方法替换为:
ContextCompat.getColor(context, R.color.my_color)
过时的getColor()方法源码
@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException {
return getColor(id, null);
}
ContextCompat.getColor()源码
public static final int getColor(Context context, int id) {
final int version = Build.VERSION.SDK_INT;
if (version >= 23) {
return ContextCompatApi23.getColor(context, id);
} else {
return context.getResources().getColor(id);
}
}