jason
jason

Reputation: 7164

How to make cursor stay in the center of edittext

I have a normal edittext like this :

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/et_word"
    android:ems="12"
    android:background="@android:color/transparent"/>

How can I make the cursor stay always in the center of edittext? No matter if user enters something or not. Thanks.

Upvotes: 1

Views: 1332

Answers (4)

krishna
krishna

Reputation: 301

<EditText 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="start" 
    android:maxLines="1"
    android:gravity="center"
    android:hint="Some hint text"
></EditText>

Upvotes: 2

Antrromet
Antrromet

Reputation: 15414

Try adding the following code

android:gravity="center"

This makes sure that your text will always be entered in the center of the EditText. By default its value is left.

<EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et_word"
        android:ems="12"
        android:gravity="center"
        android:background="@android:color/transparent"/>

Upvotes: 4

Ravi Vaghela
Ravi Vaghela

Reputation: 3420

Here you can add to property in xml file to gravity center then you can get cursor center

<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/et_word"
android:ems="12"
android:gravity="center"
android:background="@android:color/transparent"/>

That can be write from center also.

Upvotes: 1

Mr Robot
Mr Robot

Reputation: 1747

please Try adding the following code

 <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ellipsize="start" 
        android:maxLines="1"
        android:gravity="center"
        android:id="@+id/et_word"
        android:ems="12"
        android:background="@android:color/transparent"/>

Upvotes: 1

Related Questions