I am developing an app using android studio and I want to add an icon to a text in the button, like this :
here is my xml code:
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="5dp"
android:fontFamily="@font/nunito_bold"
android:text="@string/conducteur"
android:textColor="#FFFFFF"
android:textSize="12sp"
app:backgroundTint="@color/main_blue"
app:cornerRadius="20dp" />
Thank you for helping me;
You can use the app:icon
attribute to define the icon and the iconGravity
attribute to define the position.
The default value app:iconGravity="start"
<com.google.android.material.button.MaterialButton
app:iconGravity="start"
android:text="BUTTON"
app:icon="@drawable/ic_add_24px"/>
or app:iconGravity="textStart"
<com.google.android.material.button.MaterialButton
app:iconGravity="textStart"
android:text="BUTTON"
app:icon="@drawable/ic_add_24px"/>
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