2016-02-29 29 views
3

我正在嘗試在預L設備上膨脹toolbar。我使用了一個擴展爲Theme.AppCompat.Light的主題,因此屬性如下:?attr/actionBarSize應該可以工作。無法在預L設備上對工具欄充氣

但是我收到以下錯誤:

Error inflating class android.support.v7.widget.Toolbar 
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-v19/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016 

toolbarXML是這樣的:

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/material_drawer_primary" 
     android:minHeight="?attr/actionBarSize" 
     android:theme="@style/****" 
     app:popupTheme="@style/****" 
     app:contentInsetStart="72dp"/> 

,我的主題是:

<style name="****" parent="Theme.AppCompat.Light"> 
     <!-- ...and here we setting appcompat’s color theming attrs --> 
     <item name="colorPrimary">@color/material_drawer_primary</item> 
     <item name="colorPrimaryDark">@color/material_drawer_primary_dark</item> 
     <item name="colorAccent">@color/material_drawer_accent</item> 

     <!-- MaterialDrawer specific values --> 
     <item name="material_drawer_background">@color/material_drawer_background</item> 
     <item name="material_drawer_primary_text">@color/material_drawer_primary_text</item> 
     <item name="material_drawer_primary_icon">@color/material_drawer_primary_icon</item> 
     <item name="material_drawer_secondary_text">@color/material_drawer_secondary_text</item> 
     <item name="material_drawer_hint_text">@color/material_drawer_hint_text</item> 
     <item name="material_drawer_divider">@color/material_drawer_divider</item> 
     <item name="material_drawer_selected">@color/material_drawer_selected</item> 
     <item name="material_drawer_selected_text">@color/material_drawer_selected_text</item> 
     <item name="material_drawer_header_selection_text">@color/material_drawer_header_selection_text</item> 
    </style> 

是否有辦法我該如何解決這個問題?謝謝 !

EDIT1:我也試圖與Theme.AppCompat.Light.NoActionBar

回答

9

找到了答案:https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.adypg3azu

Update Android Support Library to 23.2.0 cause error: XmlPullParserException Binary XML file line #17<vector> tag requires viewportWidth > 0

似乎更新支持庫23.2.0將導致此問題

對於那些誰不不想做進一步的細節,您只需要執行以下操作:

如果你有Gradle 2.0或更高版本:

android { 
    defaultConfig { 
    vectorDrawables.useSupportLibrary = true 
    } 
} 

,或者如果你有版本1.5或以下:

android { 
    defaultConfig { 
    // Stops the Gradle plugin’s automatic rasterization of vectors 
    generatedDensities = [] 
    } 
    // Flag to tell aapt to keep the attribute ids around 
    aaptOptions { 
    additionalParameters "--no-version-vectors" 
    } 
} 
4

對於我這個固定的問題..

http://blog.autsoft.hu/do-this-when-upgrading-to-support-library-23-2/

包括必要的代碼以防鏈接被刪除/刪除

取決於您使用的Gradle版本。對於新的,2.0搖籃插件是一個內襯:

// Gradle Plugin 2.0+ 
android { 
    defaultConfig { 
    vectorDrawables.useSupportLibrary = true 
    } 
} 

而對於搖籃版本1.5(有沒有這樣的修爲較舊的搖籃版本):

// Gradle Plugin 1.5 
android { 
    defaultConfig { 
    generatedDensities = [] 
    } 

    // This is handled for you by the 2.0+ Gradle Plugin 
    aaptOptions { 
    additionalParameters "--no-version-vectors" 
    } 
} 

隨着placein這些選項你應用程序的build.gradle文件,即使在舊設備上,一切都將恢復正常。此外,不要忘記將Gradle插件升級到1.5.0或更高版本,因爲舊版本不受支持。

相關問題