不能在pre L设备上充气工具栏

Mar*_*vel 3 android

我试图toolbar在pre-L设备上充气.我使用的主题扩展了如下Theme.AppCompat.Light属性:?attr/actionBarSize应该工作.

但是我收到以下错误:

 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
Run Code Online (Sandbox Code Playgroud)

我是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"/>
Run Code Online (Sandbox Code Playgroud)

我的主题是这样的:

<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>
Run Code Online (Sandbox Code Playgroud)

有什么方法可以解决这个问题吗?谢谢 !

Edit1:我也试过了 Theme.AppCompat.Light.NoActionBar

Mar*_*vel 9

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

将Android支持库更新到23.2.0会导致错误:XmlPullParserException二进制XML文件行#17 <vector>标记需要viewportWidth> 0

似乎更新到支持库23.2.0将导致此问题

对于那些不想提供更多详细信息的人,您只需要执行以下操作:

如果您使用的是Gradle2.0或更高版本:

android {
  defaultConfig {
    vectorDrawables.useSupportLibrary = true
  }
}
Run Code Online (Sandbox Code Playgroud)

或者如果你有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"
  }
}
Run Code Online (Sandbox Code Playgroud)