Search code examples
androidfloating-action-button

FloatingActionButton showing two colors (circles)


I added a FloatingActionButton in the layout where its only parent is a CoordinatorLayout, so I don't understand where the backgroundTint color is coming from.

I tried to change the color to match the inner circle, but it changes the whole button to a solid color.

I also applied a different style, but it does not change the button at all. I fixed this problem in the past, but I don't remember how I did it.

<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" />

enter image description here


Solution

  • The gray color comes from your colorAccent defined for the app theme in style.xml. Now the @drawable/ic_action_add is a plus sign inside a filled circle. Try to use below icon instead:

    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>
    

    enter image description here

    Then set a crimson color to the FloatingActionButton's background tint and the gray one for icon tint:

    <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" />
    

    Result:

    enter image description here