篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown API <21中的矢量Drawable崩溃相关的知识,希望对你有一定的参考价值。
# Vector Drawable crash in API < 21
[SOURCE](https://stackoverflow.com/a/48237058/1602807)
In short, add this to the `onCreate` of `Application` class
```
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
```
And use `ContextCompat`, `ResourcesCompat`, `AppCompatResources` or `VectorDrawableCompat` to load the vector image as drawable, don't use `ImageView.setImageResource()`. Sample example using Glide:
```
Drawable defaultAvatar = ContextCompat.getDrawable(context, R.drawable.ic_provider_default_circle);
Glide.with(viewHolder.iv_avatar)
.load(imageURL)
.apply(RequestOptions.circleCropTransform()
.placeholder(defaultAvatar)
.error(defaultAvatar))
.transition(DrawableTransitionOptions.withCrossFade())
.into(viewHolder.iv_avatar);
```
以上是关于markdown API <21中的矢量Drawable崩溃的主要内容,如果未能解决你的问题,请参考以下文章