1、使用以下方法过时,只是过时了,并不影响使用,只是在特殊情况下,在Android4.1系统之前加载缩略图可能会出现异常,所以被谷歌废弃了。
context.getResources().getColor(R.color.txt_color_orange)
2、使用以下方法在Api19的程序会crash:NoSuchMethodError
context.getColor(R.color.txt_color_orange)
3、查看系统源码
public static final Drawable getDrawable(Context context, @DrawableRes int id) {
final int version = Build.VERSION.SDK_INT;
if (version >= 21) {
return ContextCompatApi21.getDrawable(context, id);
} else if (version >= 16) {
return context.getResources().getDrawable(id);
} else {
// Prior to JELLY_BEAN, Resources.getDrawable() would not correctly
// retrieve the final configuration density when the resource ID
// is a reference another Drawable resource. As a workaround, try
// to resolve the drawable reference manually.
final int resolvedId;
synchronized (sLock) {
if (sTempValue == null) {
sTempValue = new TypedValue();
}
context.getResources().getValue(id, sTempValue, true);
resolvedId = sTempValue.resourceId;
}
return context.getResources().getDrawable(resolvedId);
}
}
4、为了解决以上2种问题我们使用到ContextCompat来解决
ContextCompat.getDrawable(context,R.drawable.verification_code)