我想运行我的活动我收到了这个错误:
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
我的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>
我的课程扩展了AppCompatActivity
课程。
我的风格:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
我的朋友:
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'
...
答案 0 :(得分:2)
试试这个 1。使用安装最新版本的sdk manager更新设计支持库和appCompat库 2.使用Appcompat主题 3.从AppCompatActivity而不是Activity扩展您的Activity 4.尽量保持两个库的版本相同
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
5。完成所有这些后,清理您的项目并运行。
答案 1 :(得分:1)
最后这个对我有用。改变这个:
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.0.0'
进入这个:
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
答案 2 :(得分:0)
尝试移动
xmlns:app="http://schemas.android.com/apk/res-auto"
从FloatingActionButton到RelativeLayout
答案 3 :(得分:0)
从浮动按钮
中的xml布局中删除以下行 xmlns:app="http://schemas.android.com/apk/res-auto"
更改或修改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'
}
}
}
在此代码下添加必要的依赖项并重建它,运行 项目
答案 4 :(得分:0)
使Android app compat和android studio设计在同一版本中对我有用..