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"/>
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With