Brijesh Chandrakar
Brijesh Chandrakar

Reputation: 1

How to adjust android button text at centre without padding?

I searched for the solution. It can be done with paddingLeft and paddingRight set to equal values. However, the problem with this is it doesn't work well for different screens. Here is my button code.

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/sign_in_orange"
    android:background="@drawable/orange_button"
    android:text="Continue"
    android:textSize="15sp"
    android:layout_gravity="center"
    android:layout_marginTop="10dp"
    android:layout_marginRight="7dp"
    android:minHeight="35dp"
   />

The orange_button drawable is just used to attribute round edges to the button. My ultimate goal is to have a button with text centered and positioning almost same in different screens. Note that I have used linear layout in the parent xml.

Upvotes: 0

Views: 266

Answers (2)

Sahil Garg
Sahil Garg

Reputation: 262

You can use

            android:gravity="center"

Upvotes: 1

Arsen Sench
Arsen Sench

Reputation: 438

You can use android:textAlignment="center".

Upvotes: 0

Related Questions