Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

Error when using any Android Design Support Library Elements

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...