Irtiza
Irtiza

Reputation: 333

how to align the text(hint) in the center of edit text

In this code although i have used text align attribute to set the "hint" in the center of the Edit Text view. But it is not working properly.

 <EditText
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:layout_centerVertical="true"
        android:hint="Enter number here"
        android:textAlignment="center"
        android:layout_centerHorizontal="true" />

Upvotes: 1

Views: 4481

Answers (4)

Sfayn
Sfayn

Reputation: 210

You can use gravity with "center_horizontal" value or set padding top and padding bottom

Upvotes: 0

Mahesh Suthar
Mahesh Suthar

Reputation: 247

  <EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:hint="UserName" />

Upvotes: 1

Shoeb Siddique
Shoeb Siddique

Reputation: 2825

Set Gravity to center.

android:gravity="center"

Upvotes: 2

Karol Żygłowicz
Karol Żygłowicz

Reputation: 2452

try

<EditText
    ...
    android:gravity="center"
    ... />

Upvotes: 4

Related Questions