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?
IMHO,
android:gravity = right
only makes the text jusified to the right. But what you want cannot be done with this. You can call aontouch
event in thetextbox
and add the new character to the right of the current text and display it again.....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.
I have the same problem and I am able to fix this by setting
android:textDirection
in my EditText. e.gyou 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.
Starting from API Level>=17
We can use android:layoutDirection in edit text. Also
android:gravity="end"
should also works.Its works for me
ellipsize
is importantIt solves your problem