I need to center the Hint text within an EditText
in Android. How do I do this?
In order for centering of hint text to work with EditText you have to make sure android:ellipsize="start" is defined. I don't know why this makes it work, but it does.
Example pulled from personal code:
<EditText
android:id="@+id/player2Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="start"
android:gravity="center_horizontal"
android:hint="@string/player2_name"
android:inputType="textCapWords|textPersonName"
android:singleLine="true" />
use android:textAlignment="center"
in EditText , it work for me
My problem was that the EditText
wasn't big enought to fit exactly inside its parent (FrameLayout
in my case), so using just android:gravity="center"
(center_vertical, horizontal, start, or whatever) would just fit it inside the EditText
, and not in its parent, so I had to center the EditText
inside its parent using:
android:layout_gravity="center"
pd: I used android:background="@android:color/transparent"
to hide the ugly underline in the EditText
hint
I think the answer should be :
android:textAlignment="center"
use this: android:gravity="center"
I use this and worked for me
android:gravity="Left|center_vertical"