支持库VectorDrawable Resources $ NotFoundException [英] Support library VectorDrawable Resources$NotFoundException
问题描述
我正在使用设计支持库版本 23.4.0 .我已启用gradle标志:
I am using Design Support Library version 23.4.0. I have enabled the gradle flag:
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
我正在使用版本工具 23.0.2 ,但是仍然可以在KitKat或更低版本上获得Resources$NotFoundException
.
I am using build tools version 23.0.2, but still, I am getting Resources$NotFoundException
on KitKat or lower.
当我使用android:drawableLeft
或imageView.setImageResource(R.drawable.drawable_image)
时会发生这种情况.
It is occurring when I use android:drawableLeft
or imageView.setImageResource(R.drawable.drawable_image)
.
是的,我在使用可绘制对象的每个活动中都使用
And yes, I am putting this on every activity where I am using drawables
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
这是支持库的错误吗?
推荐答案
使用支持库23.4.0 ,我花了3步才使它生效:
It took 3 separate things for me to get this to work using support library 23.4.0:
-
将此添加到
build.gradle
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
将以下内容添加到Application
类的 onCreate 中
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
(从此链接的引用-" https://stackoverflow.com/a/45582033/10752962 " )
(From the reference of this link - "https://stackoverflow.com/a/45582033/10752962")
在 API小于21 中,在setContentView()
;
对于要在其中设置矢量可绘制替换的所有XML视图
For all XML views in which you are setting a vector drawable replace
android:src
使用
app:srcCompat
,并在代码中替换为:
imageView.setImageResource(...);
使用
imageView.setImageDrawable(...);
这篇关于支持库VectorDrawable Resources $ NotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!