21

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?

j0k
  • 22,600
  • 28
  • 79
  • 90
Asaf Pinhassi
  • 15,177
  • 12
  • 106
  • 130
  • I too searching about this only..If you got the answer means..Please let me know.. – Surej Dec 15 '11 at 11:12
  • 1
    Still no answer, but I found that on some devices this behavior is different that others. I work with Hebrew enabled devices and Galaxy S behavior is different than Galaxy S2. I guess its the installed ROM that matters. I havn't tested it on Ice cream sandwich yet, where RTL language support comes as standard. If my question was relevant to you, I would appreciate it if you click ^ (up) on it. – Asaf Pinhassi Dec 15 '11 at 16:47
  • If your app is not multilingual, you can align the TextView field only to the right (so it could "stretch" to the left). It works when the field is a single line. – Asaf Pinhassi Dec 15 '11 at 16:52
  • have you found any solution to this problem please answer this here http://stackoverflow.com/questions/11314356/hebrew-keyboard-changes-edittext-gravity – Aashish Bhatnagar Jul 04 '12 at 15:33
  • Try this answer: http://stackoverflow.com/a/6624186/758458 – howettl Jan 21 '12 at 00:08
  • [Try this... for RTL text direction at run time.][1] [1]: http://stackoverflow.com/questions/5083768/can-you-make-an-edittext-input-from-right-to-left/21397832#21397832 – Silambarasan Poonguti Jan 28 '14 at 05:54
  • Check this answer it contains a workaround, http://stackoverflow.com/a/34927271/1826581 – Mohamed Fadl Allah Jan 21 '16 at 15:14

5 Answers5

19

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

Poovizhirajan N
  • 1,263
  • 1
  • 13
  • 29
2

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.

ChinLoong
  • 1,735
  • 24
  • 26
1

I have the same problem and I am able to fix this by setting android:textDirection in my EditText. e.g

android:textDirection="inherit"

you can change the value of textDirection as per your requirement. I have taken it as inherit because user are able to change the language with in app. So if user has selected language like english or hindi then it will start typing from left-to-right direction, but if user has selected language like urdu then it will start typing right-to-left direction.

For this your app minimum API level should be 17.

Rahul Sharma
  • 12,515
  • 6
  • 21
  • 30
0

IMHO, android:gravity = right only makes the text jusified to the right. But what you want cannot be done with this. You can call a ontouch event in the textbox and add the new character to the right of the current text and display it again.....

D.J
  • 1,439
  • 1
  • 12
  • 23
viks
  • 404
  • 2
  • 6
  • 14
0

Starting from API Level>=17

We can use android:layoutDirection in edit text. Also android:gravity="end" should also works.

Pravin Divraniya
  • 4,223
  • 2
  • 32
  • 49