Set FAB icon color Set FAB icon color android android

Set FAB icon color


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


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 drawableDrawable myFabSrc = getResources().getDrawable(android.R.drawable.ic_input_add);//copy it in a new oneDrawable willBeWhite = myFabSrc.getConstantState().newDrawable();//set the color filter, you can use also Mode.SRC_ATOPwillBeWhite.mutate().setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY);//set it to your fab button initialized beforemyFabName.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"