3

I am trying to inflate toolbar on pre-L devices. I use a theme which extends Theme.AppCompat.Light so attributes like: ?attr/actionBarSize should work.

However I am getting the following error:

 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

My toolbar from XML is this:

<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"/>

and my Theme is this:

<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>

Is there a way how can I solve this ? Thank you !

Edit1: I also tried with Theme.AppCompat.Light.NoActionBar

Marian Pavel
  • 2,726
  • 8
  • 29
  • 65

2 Answers2

9

Found the answer: 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

Seems that updating to support library 23.2.0 will cause this problem

For those who don't want to make further details, you only need to do the following:

If you have Gradle version 2.0 or above:

android {
  defaultConfig {
    vectorDrawables.useSupportLibrary = true
  }
}

or if you have version 1.5 or below:

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"
  }
}
Community
  • 1
  • 1
Marian Pavel
  • 2,726
  • 8
  • 29
  • 65
4

For me this fixed the problem..

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

Including essential code in case the link gets deleted/removed

Depending on the Gradle version you use. For the new, 2.0 Gradle plugin it is a one liner:

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

And for Gradle version 1.5 (there is no such fix for older Gradle versions):

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

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

With these options in placein your app's build.gradle file, everything will be back to normal even on older devices. Also, don't forget to upgrade the Gradle plugin to 1.5.0 or newer, as older versions are not supported.

Amit Tumkur
  • 2,752
  • 26
  • 27