Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get material icon button in Android?

How can I get a material button in android? I have tried this code but don't know how to include an image like this:

<com.google.android.material.button.MaterialButton
    android:id="@+id/material_button"
    style="@style/Widget.MaterialComponents.Button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add to Cart"/>

enter image description here

like image 363
Android Dev Avatar asked Jul 28 '19 03:07

Android Dev


People also ask

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.

How do I use material icons on Android?

In Android Studio, right-click on the “drawable” folder and select “New” » “Vector Asset”. From there, for “Asset Type”, select “Local file (SVG, PSD)” Enter a name for the icon. Enter the path to your icon, or use the folder icon to choose the icon in your file explorer.

What is material button in Android?

Material Button is a customizable button component with updated visual styles. This button component has several built-in styles to support different levels of emphasis, as typically any UI will contain a few different buttons to indicate different actions.


1 Answers

For Material Button use icon and iconGravity properties like below:

<com.google.android.material.button.MaterialButton
        style="@style/Widget.MaterialComponents.Button.Icon"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Icon Button"
        app:icon="@drawable/your_icon"
        app:iconGravity="textStart"/>

Go through docs for better understanding:Here

like image 52
Sumit Shukla Avatar answered Sep 23 '22 13:09

Sumit Shukla