I'm trying to add a color vector icon in an ExtendedFloatingActionButton from google material but it is showing a black background in the icon.
On Preview of layout, it looks alright but when run on mobile it shows black background near the icon.
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/floating_btn_take_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="@dimen/dimen_20dp"
android:text="@string/txt_take_test"
android:textColor="@color/primaryColor"
app:backgroundTint="@color/color_white"
app:elevation="@dimen/dimen_10dp"
app:icon="@drawable/ic_color_icon"
app:iconTintMode="add"
app:layout_anchorGravity="bottom|center"
app:rippleColor="@color/secondaryColor"
app:shapeAppearanceOverlay="@style/ShapeAppearance_Button" />
<style name="ShapeAppearance_Button" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">@dimen/dimen_10dp</item>
<item name="android:layout_marginBottom">@dimen/dimen_30dp</item>
</style>
How to remove the black background around the icon?
If I understand correctly you are trying to add a icon that has different colours to a FAB?
When doing that, make sure you add app:tint="@null"
.
In your case the xml should look like this.
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/floating_btn_take_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="@dimen/dimen_20dp"
android:text="@string/txt_take_test"
android:textColor="@color/primaryColor"
app:backgroundTint="@color/color_white"
app:elevation="@dimen/dimen_10dp"
app:icon="@drawable/ic_color_icon"
app:layout_anchorGravity="bottom|center"
app:rippleColor="@color/secondaryColor"
app:shapeAppearanceOverlay="@style/ShapeAppearance_Button"
app:tint="@null" />
<style name="ShapeAppearance_Button" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">@dimen/dimen_10dp</item>
<item name="android:layout_marginBottom">@dimen/dimen_30dp</item>
</style>