[英]Error inflating class android.support.design.widget.FloatingActionButton - android
I want to run my activity I got this error : 我想运行我的活动我收到了这个错误:
android.view.InflateException: Binary XML file line #21: Error inflating class android.support.design.widget.FloatingActionButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class android.support.design.widget.FloatingActionButton
my xml code : 我的xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<ListView
android:id="@+id/listview_diary"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:divider="@null"
android:dividerHeight="16dp"
android:fadingEdge="none"
android:fitsSystemWindows="true"
android:padding="12dp"
android:scrollbars="none"
android:background="@android:color/white"/>
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fab_add_diary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:clickable="true"
android:padding="8dp"
android:src="@mipmap/ic_add"
app:backgroundTint="@color/colorPrimary"
app:borderWidth="0dp"/>
</RelativeLayout>
my class extended a AppCompatActivity
class. 我的类扩展了AppCompatActivity
类。
my style : 我的风格 :
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
my gradle : 我的朋友:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "***.***.***"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
jackOptions {
enabled true
}
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
debuggable false
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dexOptions {
javaMaxHeapSize "2g"
incremental true
preDexLibraries = false
}
}
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url 'https://raw.github.com/felipecsl/m2repository/master' }
// maven { url "https://jitpack.io" }
mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.github.florent37:materialviewpager:1.2.0@aar') {
transitive = true
}
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.android.support:support-v4:24.0.0'
...
Try this 尝试这个
1 . 1。 update design support library and appCompat library using sdk manager which installs the latest versions. 使用安装最新版本的sdk管理器更新设计支持库和appCompat库。
2. Use Appcompat theme. 2.使用Appcompat主题。
3. Extend your Activity from AppCompatActivity instead of Activity. 3.从AppCompatActivity而不是Activity扩展您的Activity。
4. Try to keep the version of both libraries same 4.尽量保持两个库的版本相同
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
5. After all these clean your project and run . 5.完成所有这些后清理您的项目并运行。
This one work for me finally. 这个最终对我有用。 Change this: 改变这个:
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.0.0'
Into this : 进入:
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
尝试将xmlns:app="http://schemas.android.com/apk/res-auto"
从FloatingActionButton移至RelativeLayout
Remove the following line from xml layout in Floating Button 从浮动按钮中的xml布局中删除以下行
xmlns:app="http://schemas.android.com/apk/res-auto"
Change or modify code in the Gradle file 更改或修改Gradle文件中的代码
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.java.user.sample"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Add the necessary dependency below this code and rebuild it ,run the projects 在此代码下添加必要的依赖项并重建它,运行项目
使Android应用程序compat和Android工作室设计在同一版本对我有用..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.