Set FAB icon color
UPDATE 2
If you are using com.google.android.material.floatingactionbutton.FloatingActionButton
, use app:tint
app:tint="@android:color/white"
UPDATE
Refer to the answer of @Saleem Khan which is the standard way to set the app:tint
using:
android:tint="@android:color/white"
via XML on FloatingActionButton
.
OLD (June 2015)
This answer was written before October 2015, when android:tint
on FloatingActionButton
was supported only with API >= 21.
You can change it programmatically using ColorFilter
.
//get the drawable
Drawable myFabSrc = getResources().getDrawable(android.R.drawable.ic_input_add);
//copy it in a new one
Drawable willBeWhite = myFabSrc.getConstantState().newDrawable();
//set the color filter, you can use also Mode.SRC_ATOP
willBeWhite.mutate().setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY);
//set it to your fab button initialized before
myFabName.setImageDrawable(willBeWhite);
If you are using Material Components
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_gravity="bottom|end"
app:fabSize="normal"
app:tint="@color/colorAccent"
app:srcCompat="@drawable/ic_google"/>
If you want to use icon default color, change app:tint="@null"
Using android:tint property you can set the color like this
<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:tint="@android:color/white"
android:src="@android:drawable/ic_input_add"
/>