android - 膨胀类 android.support.design.widget.CoordinatorLayout 时出错

标签 android floating-action-button

我想在我的应用程序中使用 FloatingActionButton,我读到了:https://guides.codepath.com/android/Floating-Action-Buttons#google-s-official-support-library但是当我运行 Activity 时出现此错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xavier_laffargue.podcast/com.xavier_laffargue.podcast.ACT_Test}: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout

XML 文件

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/lvToDoList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="24dp"
        android:src="@drawable/ic_action_refresh"
        app:layout_anchor="@id/lvToDoList"
        app:layout_anchorGravity="bottom|right|end" />

</android.support.design.widget.CoordinatorLayout>

Gradle

*apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.xavier_laffargue.podcast"
        minSdkVersion 21
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:appcompat-v7:22.2.0'
    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:cardview-v7:21.0.+'
    compile 'com.android.support:recyclerview-v7:21.0.+'

}

最佳答案

对于那些使用 AndroidX 依赖

随着依赖关系的改变,XML也必须改变。

来自

<android.support.design.widget.CoordinatorLayout 

<androidx.coordinatorlayout.widget.CoordinatorLayout

关于android - 膨胀类 android.support.design.widget.CoordinatorLayout 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30571097/

相关文章:

android - float 操作按钮中的加号图标在 Android pre-Lollipop 中未正确呈现

Angular Material 5 设置 fab 按钮默认颜色

android - 当呈现模态、iOS Actionsheet、选择器组件时,React Native 上的 float 按钮 (FAB) 不会停留在顶部

java - File.exists() 方法总是返回 true,即使文件不存在

java - float 操作按钮菜单不随标题滚动

java - 以不同的间隔多次重试代码段

android - 有没有办法在 Android 上运行 Python?

Android Sliding Tabs 切断 Fragments 和 FAB 不工作

android - 如何在线性布局中居中 TextView

android - 如何在电子邮件正文中创建表格