显示两种颜色(圆圈)的 FloatingActionButton

Pit*_*tos 0 android floating-action-button

我在布局中添加了一个 FloatingActionButton,其唯一的父级是 CoordinatorLayout,所以我不明白 backgroundTint 颜色来自哪里。

我尝试更改颜色以匹配内圆,但它将整个按钮更改为纯色。

我还应用了不同的样式,但它根本没有改变按钮。我过去解决过这个问题,但我不记得我是怎么做到的。

<android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:src="@drawable/ic_action_add"
        app:layout_anchor="@+id/edit_layout"
        app:layout_anchorGravity="bottom|right|end" />
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

ami*_*phy 5

灰色来自您colorAccent为应用程序主题定义的style.xml. 现在@drawable/ic_action_add是一个实心圆圈内的加号。尝试使用下面的图标代替:

ic_add_black_24dp.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
    <path
        android:fillColor="#000000"
        android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
</vector>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

然后将FloatingActionButton的背景色调设置为深红色,将图标色调设置为灰色:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="16dp"
    app:layout_anchor="@+id/edit_layout"
    app:layout_anchorGravity="bottom|right|end"
    app:tint="#404D54"
    app:backgroundTint="#6F303A"
    app:srcCompat="@drawable/ic_add_black_24dp" />
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述