42

アプリケーションで FloatingActionButton を使用したいのですが、これを読みました: 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.+'

}
4

13 に答える 13

41

Activity を使用する場合は AppCompatActivity に変更してください。おそらくActivityだとエラーになります。

于 2015-06-02T12:27:33.663 に答える
18

compile 'com.android.support:design:23.0.1'プロジェクトのbuild.gradleファイルに入れてください

于 2016-05-21T06:08:41.607 に答える
4

これらの依存関係を gradle ファイルに追加します。これにより、問題が解決する場合があります。

dependencies {
   compile 'com.android.support:appcompat-v7:23.1.1'
   compile 'com.android.support:design:23.1.1'
   ...
}
于 2016-10-06T17:34:03.900 に答える
0

AndroidX Dependency を使用している方向け。xml ファイルで、すべての

 android.support.???

CoordinatorLayout 内のノード (含まれている ActionBars など) も次のように置き換えられます。

androidx.??? (or com.google.android.???)

もの。

于 2019-06-20T10:03:41.710 に答える