How to set text set on center position when using DrawableLeft on a button?
JavaScript
x
<Button
android:layout_marginTop="80dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:background="@drawable/rectangle_round_white"
android:drawableLeft="@drawable/icon_google"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:elevation="5dp"
android:text="start with google"
android:textAlignment="center"
android:textSize="11dp"/>
the text START WITH GOOGLE
is not placed on the center.
How to center it?
Advertisement
Answer
One hacky solution is to make a transparent png file or the same color as the background with the exact dimensions of icon_google
and set it as drawableRight like so:
JavaScript
<Button
android:layout_marginTop="80dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:background="@drawable/rectangle_round_white"
android:drawableLeft="@drawable/icon_google"
android:drawableRight="@drawable/transparent_icon_google"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:elevation="5dp"
android:text="start with google"
android:textAlignment="center"
android:textSize="11dp"/>