浮动操作按钮不起作用

时间:2017-06-28 11:20:39

标签: android

我已将浮动操作按钮添加到我的应用中,并且应用崩溃时出现错误:

Error inflating class android.support.design.widget.FloatingActionButton

Button在Android 7上运行良好(使用Nexus 5模拟器,api 24和25测试),但不适用于API 23或更低版本。据我从文档中了解,FAB应该适用于此版本的Android。我该如何修复这个错误?以下是我的FAB代码:

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_add_black_48dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_marginRight="16dp"
    android:layout_marginBottom="16dp"
    android:id="@+id/float_btn"
    android:backgroundTint="@color/category_family"
    app:fabSize="normal" />

和Gradle文件:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion '25.0.3'

defaultConfig {
    applicationId "com.example.android.miwok"
    minSdkVersion 15
    targetSdkVersion 23
    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 'org.immutables:gson:2.5.3'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}



apply plugin: 'com.google.gms.google-services'

1 个答案:

答案 0 :(得分:0)

您使用了错误的属性

更改如下:

android:backgroundTint="@color/category_family"

app:backgroundTint="@color/category_family"