0

I am able to change the color of the FAB but I couldn't change the color of the text. The icon that I am using is white but it is shown as black. Please see my xml

 <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin"
            android:layout_marginBottom="16dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.954"
            app:layout_constraintStart_toStartOf="parent"
            android:backgroundTint="@color/blue"
            app:srcCompat="@drawable/ic_time"
            android:tint="@android:color/white" />

enter image description here

Ibanez1408
  • 4,550
  • 10
  • 59
  • 110
  • 2
    Does this answer your question? [Set FAB icon color](https://stackoverflow.com/questions/31113819/set-fab-icon-color) – Rayan Hatout Mar 29 '22 at 01:16
  • 1
    ^ The accepted answer there has the right suggestion. For future reference, material.io has docs for all of the Material Components widgets, and tables that show which XML attributes to use for what; e.g, https://material.io/components/buttons-floating-action-button/android#regular-fabs. – Mike M. Mar 29 '22 at 01:21
  • I don't know what's happening but somehow I still can't get the white text. Please see my edit. – Ibanez1408 Mar 29 '22 at 01:41
  • 1
    You want `app:tint` instead: https://stackoverflow.com/a/31114037. – Mike M. Mar 29 '22 at 01:41

1 Answers1

0

Use app:tint to change the tint of icon. You can achieve required output by using the code below.

<com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin"
            android:layout_marginBottom="16dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.954"
            app:layout_constraintStart_toStartOf="parent"
            android:backgroundTint="@color/blue"
            app:srcCompat="@drawable/ic_time"
            app:tint="@android:color/white" />
Ammar Abdullah
  • 802
  • 4
  • 8
  • 21