Maedeh HM Maedeh HM - 3 months ago 7
Android Question

Making text vertically centered in a button

I have buttons in

RelativeLayout
. Height and width are not
wrap_content
. I noticed that the text in
Button
is not vertically centered. How can I fix this problem in my code?

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="40dp"
android:text="&lt;"
android:id="@+id/buttonPreviousDay"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/editTextShowDate"
android:layout_marginEnd="10dp"
android:textSize="20dp"
android:background="@drawable/button_shape"
android:textStyle="bold" />

Answer

you need to set padding

    android:padding="5dp"
    android:gravity="center"
    android:textSize="12sp"
Comments