How do I position the cursor on the right in EditT

2019-02-05 23:18发布

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?

5条回答
Viruses.
2楼-- · 2019-02-06 00:00

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.....

查看更多
不美不萌又怎样
3楼-- · 2019-02-06 00:05

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.

查看更多
男人必须洒脱
4楼-- · 2019-02-06 00:15

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.

查看更多
姐就是有狂的资本
5楼-- · 2019-02-06 00:20

Starting from API Level>=17

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

查看更多
Emotional °昔
6楼-- · 2019-02-06 00:21

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

查看更多
登录 后发表回答