Search code examples
androidandroid-xmlandroid-drawableandroid-button

How to set drawable with text in button android


I am trying to set drawable in my button but its not showing properly. Here is what I want to achieve enter image description here

but I am unable to get the required results.

This is what I am doing

<androidx.appcompat.widget.AppCompatButton
                android:id="@+id/btnShareStore"
                style="@style/yellowButton"
                android:layout_marginTop="@dimen/margin_large"
                android:layout_marginBottom="@dimen/margin_small"
                android:layout_weight="1"
                android:drawableStart="@drawable/ic_vector_share"
                android:text="@string/lbl_share_store"
                android:layout_marginStart="@dimen/margin_large"
                android:layout_marginEnd="@dimen/margin_small"/>

and this is how it looks like

enter image description here

How can I move drawable to the adjacent left side of text?

Any help will be highly appreciated


Solution

  • You can try with this, keep in mind that it will need your app theme to be a descendant of MaterialTheme.

    <com.google.android.material.button.MaterialButton
            app:icon="@drawable/icon_search"
            android:text="Hello"
            app:iconGravity="textStart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>