FloatingActionButton:不支持设置自定义背景

时间:2017-12-23 09:54:01

标签: android kotlin floating-action-button

    <android.support.design.widget.FloatingActionButton
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/insert_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/add"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="20dp"
        android:layout_alignBottom="@id/list_view"
        android:layout_alignRight="@id/list_view"
        android:background="#649696"
        />

这段代码没问题,但是在两行之后添加了crask

        android:backgroundTint="#649696"
        app:rippleColor="#FFFFFF"

崩溃日志:

在Android 4.1之前,方法android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter,android.content.res.ColorStateList,android.graphics.PorterDuff $ Mode)会有错误的重写了android.graphics.drawable.Drawable中的package-private方法 I / FloatingActionButton:不支持设置自定义背景。

等级依赖:

compileSdkVersion 27
defaultConfig {
    applicationId ""
    minSdkVersion 23
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

谁能告诉我怎样才能解决这个问题

4 个答案:

答案 0 :(得分:1)

  

您需要在fab按钮中添加app:backgroundTint="@color/your_color"以更改背景颜色   按钮

 <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            app:elevation="2dp"
            android:layout_margin="16dp"  
            android:src="@drawable/ic_close_black_24dp"
            app:backgroundTint="@color/colorPrimary"
            app:fabSize="normal" />

答案 1 :(得分:0)

使用以下属性进行背景

<android.support.design.widget.FloatingActionButton
    ...
    app:backgroundTint="@color/ic_action"
    android:src="@drawable/ic_plus" />

删除android:backgroundTint

答案 2 :(得分:0)

这是一个愚蠢的错误,当在系统api之外使用时需要使用app作为命名空间而不是android 所以正确的代码是

应用程式:backgroundTint = “#649696”

答案 3 :(得分:0)

不幸的是,如果您甚至没有设置背景或色彩,也会显示此警告。但是,要摆脱它,可以设置属性android:background="@null",这将根据用户在official materials github repository中的建议将其忽略。 (此问题的原因是内部问题,其中调用了一些设置方法,可能会在将来的材料设计库发行版中修复该问题)