Home » Android » android – Material Button Icon is showing without color

android – Material Button Icon is showing without color

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am using the following material button:

<android.support.design.button.MaterialButton
            android:id="@+id/bFavourite"         style="@style/Widget.MaterialComponents.Button.UnelevatedButton.Icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:insetTop="0dp"
            android:insetBottom="0dp"
            android:textAllCaps="false"
            android:textSize="20sp"
            app:backgroundTint="@color/main_dark_blue"
            app:backgroundTintMode="src_over"
            app:cornerRadius="0dp"
            app:icon="@drawable/heart_filled"
            app:iconGravity="textStart"
            app:iconPadding="0dp" />

heart_filled is a png of a red heart. However the icon is showing without any color (i.e., a white heart).
Why is the actual color of the image not showing?
Thank you

How to&Answers:

You can try to set the iconTint attribute of the Button:

app:iconTint="#ffffff"

Answer:

May be you are looking for this set iconTint to null

<com.google.android.material.button.MaterialButton
            android:id="@+id/btnGoogle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginStart="@dimen/_2sdp"
            android:layout_weight="1"
            app:icon="@drawable/ic_google"
            app:iconGravity="textStart"
            app:iconTint="@null"
            android:elevation="@dimen/_10sdp"
            android:text="@string/string_google"
            android:textAllCaps="false"
            app:rippleColor="@color/colorBlueShade1"
            app:cornerRadius="@dimen/_20sdp"
            app:backgroundTint="@color/colorWhite"
            android:textColor="@color/colorPrimary" />

Achieved output
enter image description here

I know its too late but it can be helpful to others
Thanks

Happy coding 🙂

Answer:

You can use app:iconTint="@android:color/white" because they mention this in docs MaterialButton Docs