当前位置: 首页 > 知识库问答 >
问题:

对android类进行充气时出错。支持设计小装置。协调布局

公羊灿
2023-03-14

我想在我的应用程序上使用floatingaction按钮,我阅读了以下内容:https://guides.codepath.com/android/Floating-Action-Buttons#google-s-official-support-library,但当我运行该活动时,出现以下错误:

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>

格拉德尔

*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.+'

}

共有3个答案

黄沈浪
2023-03-14

只需在FloatingActionButton(app中使用这一行,而不是android):

app:backgroundTint="@color/colorAccent"
庄飞
2023-03-14

如果使用Activity,请将其更改为AppCompatActivity。当它是活动时,可能会成为错误。

凤柏
2023-03-14

对于使用AndroidX的用户

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

从…起

<android.support.design.widget.CoordinatorLayout 

<androidx.coordinatorlayout.widget.CoordinatorLayout
 类似资料: