Glide 在Android5.0以下 加載Vector 文件導致app崩潰

問題:項目中使用了Vector 文件並使用Glide 去加載圖片 ,但是4.4手機在加載的時候就會出現異常。

異常信息:

Resources$NotFoundException: File res/drawable/logo.xml from drawable resource ID #0x7f0800b8. If the resource you are trying to use is a vector resource, you may be referencing it in an unsupported way. See AppCompatDelegate.setCompatVectorFromResourcesEnabled() for more info.

檢查:

項目中build.gradle都配置好了:

defaultConfig {
    ....
    vectorDrawables.useSupportLibrary = true
    ....
}

也在BaseActivity中添加了

static {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

但是問題依舊,所以應該是Glide 的兼容性問題。

處理方法:

需要將vector文件先抽取成drawable然後再加載,即可成功加載。

 Drawable drawable = AppCompatResources.getDrawable(mContext, R.drawable.logo);

            Glide.with(mContext).load(item.getImg()).dontAnimate().error(drawable).into((AppCompatImageView)
                    helper.getView(R.id.addassets_token_img_iv));
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章