Error when using any Android Design Support Library Elements

Joshua McWilliams picture Joshua McWilliams · May 30, 2015 · Viewed 54.9k times · Source

Error inflating anything from the design support library

xml

<android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

build.gradle

dependencies {
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:support-v13:22.2.0'
    compile 'com.android.support:appcompat-v7:22.2.0'

project build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

Error:

Binary XML file line #115: Error inflating class
android.support.design.widget.FloatingActionButton

My Sdk Manager everything is up to date.
SDK Manager

Answer

CptSausage picture CptSausage · May 31, 2015

In addition to Emmanuel's answer you could be facing the following problem.

It seems like the design library components need a style which is based on an AppCompat Theme. So try to use "Theme.AppCompat.[...]" as a parent in your style.xml.

Example:

<!-- Base application theme. -->
<style name="AppTheme" parent="Base.AppTheme">
    <!-- Customize your theme here. -->
</style>

<style name="Base.AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:colorPrimary">@color/primary</item>
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <item name="android:colorAccent">@color/accent</item>
</style>

Then add the following to your build.gradle as well:

compile 'com.android.support:appcompat-v7:22.2.0'

Additionally you should update the following lines in your gradle as well:

classpath 'com.android.tools.build:gradle:1.2.3'
compileSdkVersion 22
buildToolsVersion '22.0.1'
targetSdkVersion 22