Distance between icon and text in the Button
Asked Answered
B

2

8

I have a button defined in the XML shown below:

<Button
    android:layout_width="@dimen/logo_menu_width"
    android:layout_height="@dimen/logo_menu_height"
    android:layout_margin="@dimen/logo_menu_margins"
    android:gravity="left|center_vertical"
    android:background="@drawable/selector_blue"
    android:drawableStart="@drawable/ic_action_settings"
    android:paddingStart="6dp"
    android:text="Options"
    android:textColor="@color/blue_light"
    android:textSize="@dimen/logo_menu_text"
    android:id="@+id/buttonOptions"
    android:layout_gravity="center_horizontal" />

How to increase distance between icon (set with drawableStart) and text? Text alignment is set to left. paddingStart is set to 6dp, but it applies to icon only, not the text.

Is it possible to set it with XML file?

I know I can do this using LinearLayout - containing both ImageView and TextView, but I am trying to limit nesting of the views.

Blat answered 10/8, 2014 at 19:30 Comment(0)
G
20

Use the android:drawablePadding attribute.

Goal answered 10/8, 2014 at 21:7 Comment(2)
Damn, so simple. Thanks a lot! :)Blat
In Material is not working, for Material3 use app:iconPaddingMatheson
M
4

app:iconPadding is used to determine the space between icon and text in MaterialButton

Mainly answered 22/9, 2023 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.