2016-12-19 21 views
2

我正在制作一个带有几个片段的android应用程序。在其中一个片段中,我有一个带有后退箭头的工具栏作为图像按钮。
在XML文件中,我有“app:srcCompat”属性,但在使用此属性时出现错误:“要使用VectorDrawableCompat,您需要设置'android.defaultConfig.vectorDrawables.useSupportLibrary = true'使用Vector Drawable Compat

+1

那么......它已经告诉你解决方案! '要使用VectorDrawableCompat,您需要设置'android.defaultConfig.vectorDrawables.useSupportLibrary = true'' –

+0

我有同样的问题,没有执行建议的解决方案,但一切适用于新旧设备。我想知道为什么这个警告一直出现,如果他们似乎没有影响任何东西。 – Gustavo

+1

@ModularSynth对于新手来说,目前还不清楚这应该添加在哪里,更不用说如何。 –

回答

-1

添加到您的ImageButton:

tools:ignore="VectorDrawableCompat" 
8

在你的模块build.gradle文件,你需要加入这一行:

apply plugin: 'com.android.application' 

android { 
    ... 

    defaultConfig { 
     ... 

     vectorDrawables.useSupportLibrary = true // This line here 
    } 
    ... 
} 

... 
0

这一行添加到您的摇篮文件下defaultConfig块:

vectorDrawables.useSupportLibrary = true 

另外,你需要在每一个活动或片段在那里你引用可绘制的图像,而不是在srcCompat添加的代码块:

static { 
     AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); 
    } 
相关问题