Why is my FloatingActionButton icon black?

The FloatingActionButton class from AndroidX uses the colorOnSecondary theme attribute to tint its icon.

https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/floatingactionbutton/res/values/styles.xml#L39

If you follow the MaterialComponents theme definitions down into the base definitions, you'll see that the default value for colorOnSecondary is design_default_color_on_secondary... and that is defined as #000000.

https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/color/res/values/colors.xml#L26

You can fix this by either adding the app:tint attribute directly to your FloatingActionButton or by re-defining @color/colorOnSecondary in your theme to be whatever you want.


If you're using AndroidX, to change the color of the icon you must use app:tint opposed to android:tint

<com.google.android.material.floatingactionbutton.FloatingActionButton
    style="@style/Widget.MaterialComponents.FloatingActionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="16dp"
    app:backgroundTint="@color/colorPrimary"
    app:tint="@color/white"
    app:srcCompat="@drawable/ic_add"
/>

I have an icon(vector) with multiple colors(attached file) but I cannot use app:tint="@color/white" because my icon's color turns to single color such as white and I did not need this.

So I Fixed my problem with set setting app:tint to null:

  app:tint="@null"

My Icon (SVG) :

enter image description here