Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material Button Icon is showing without color

Tags:

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

like image 327
Snake Avatar asked Nov 24 '18 19:11

Snake


People also ask

How do I disable MaterialButton?

Goto your layout/activity_filename. xml file and add this android:enabled="false" to your button widget.

How do I add an icon to a material button?

Add icons to the start, center, or end of this button using the app:icon , app:iconPadding , app:iconTint , app:iconTintMode and app:iconGravity attributes. If a start-aligned icon is added to this button, please use a style like one of the ". Icon" styles specified in the default MaterialButton styles.

What is the difference between Button and material button in Android Studio?

Material Buttons are slightly different to traditional Android buttons in that they do not include additional insets (4dp on the left/right) and have more letter-spacing, different default colors and other attributes that improve legibility and affordance amongst other components.


1 Answers

Maybe 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 Material button with colored icon

like image 149
Shrenik Shah Avatar answered Oct 11 '22 17:10

Shrenik Shah