无法在前L设备上

时间:2016-02-29 13:37:13

标签: android

我试图在pre-L设备上充气toolbar。我使用了一个扩展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

来自toolbar的我XML就是:

<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

2 个答案:

答案 0 :(得分: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"
  }
}

答案 1 :(得分:4)

对我来说,这解决了问题..

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

包括基本代码以防链接被删除/删除

取决于您使用的Gradle版本。对于新的2.0 Gradle插件,它是一个单线程:

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

对于Gradle 1.5版(对于较旧的Gradle版本没有此类修复):

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

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

在app的build.gradle文件中使用这些选项后,即使在较旧的设备上,一切都将恢复正常。此外,不要忘记将Gradle插件升级到1.5.0或更高版本,因为不支持旧版本。