How do I position the cursor on the right in EditText

北城以北 提交于 2019-11-30 08:18:14

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

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

Starting from API Level>=17

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

viks

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!