2016-12-19 20 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); 
    } 
相關問題