Android获取Drawable时通常使用方法
getResources().getDrawable(resId);
此方法提示过时,使用如下替代方案:
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
drawable = getResources().getDrawable(resId, null);
} else {
drawable = getResources().getDrawable(resId);
}
编译过程中还是报方法过时问题,最终解决方案:
Drawable drawable = ContextCompat.getDrawable(Context,resId);