How to add margin to an image inside of custom button

342 views Asked by At

I have a custom Button with a centered (default) text. I want to add an image just 8dp left of this text which are have to be in custom button.

I can add it only left with drawableLeft attribute. I want to make it more centered.

enter image description here

This is my custom button.

How to make centered that image? (8dp left of text)

1

There are 1 answers

2
Gabriele Mariotti On

Just use the MaterialButton with the app:iconGravity attribute.

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

enter image description here

You can change the padding between the icon and the text using app:iconPadding="xxdp" attribute.

Example with app:iconPadding="0dp":

enter image description here