Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I position the cursor on the right in EditText

Tags:

My application uses RTL language (right to left).

When the EditText field gets focus, the cursor appears on the left and only when the user starts to type, the cursor (and the RTL text) moves right. When the user clicks "enter" to start a new line, the cursor moves to the left again.

When I use android:gravity="right", the cursor is OK (on the right) but as the user starts to type the text always moves to the the other side (RTL text moves left).

Any ideas how I can align text to the right AND keep the text direction?

like image 652
Asaf Pinhassi Avatar asked Oct 18 '11 20:10

Asaf Pinhassi


People also ask

How do I change the cursor position in EditText?

Say in your xml's edittext section, add android:paddingLeft="100dp" This will move your start position of cursor 100dp right from left end. Same way, you can use android:paddingRight="100dp" This will move your end position of cursor 100dp left from right end.

How do I move my cursor to the end of EditText?

setSelection(editText. getText(). length()); This places cursor to end of EditText.

How do I scroll up layout when clicking on EditText?

try this android:windowSoftInputMode="adjustResize" in your activity in manifest file.


2 Answers

Its works for me

      <EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:ellipsize="end"
            android:gravity="right" />

ellipsize is important

It solves your problem

like image 109
Poovizhirajan N Avatar answered Oct 30 '22 14:10

Poovizhirajan N


You might want to look into the native RTL support that was introduced in Android 4.2 Jelly Bean.

http://developer.android.com/about/versions/jelly-bean.html

Android 4.2 introduces full native support for RTL (right-to-left) layouts, including layout mirroring. With native RTL support, you can deliver the same great app experience to all of your users, whether their language uses a script that reads right-to-left or one that reads left-to-right.

like image 42
ChinLoong Avatar answered Oct 30 '22 13:10

ChinLoong