Cursor in center position in android

android, android-edittext

Solution

You can try this

<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:textAlignment="center"
android:ellipsize="end"
android:gravity="center"/>

Problem

I am working with Android app which contains login screen. In my login screen, I have Username and Password `EditTtext` fields. In `EditText`, I need the hint as "Enter your Username" in center aligned, so I set the gravity as "center" but now, the problem is that the cursor is also visible in center position, I need cursor in left positioned. And I also tried the below coding. ``` edtUserName.setSelection(1); ``` This is my xml code: ``` <EditText android:id="@+id/edt_login_username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bg_txt_field" android:ellipsize="start" android:focusableInTouchMode="true" android:hint="Enter Username" android:maxLines="1" android:singleLine="true" android:textStyle="italic" android:typeface="serif" android:gravity="center"> </EditText> ``` Please help me to solve this problem. Thanks in advance.

Original source