这个处理方法可以在getDrawable 前面添加 ContextCompat 如下
imageView.setImageDrawable(ContextCompat.getDrawable(this,R.mipmap.ic_launcher));
这样就没有报错提示了
具体原因我们可以通过源码看到,前面添加了ContextCompat 之后 源码里面添加了判断
public static Drawable getDrawable(@NonNull Context context, @DrawableRes int id) {if (Build.VERSION.SDK_INT >= 21) {return context.getDrawable(id);} else if (Build.VERSION.SDK_INT >= 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);}}