How to set the cursor to the right (EditText)?

2020-02-07 01:54发布

How to set the cursor to the right with right align and hint text?
Is it possible?

I have a AutoCompleteTextView and a EditText with Text right align and an hint text. Now if one of them is focused the curser is before the hint and not at the end of the line. So it looks like now it's bad...

I've also tried to set the cursor position, but it didn't help of course.

<AutoCompleteTextView
    android:id="@+id/input_snm"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/input_ipAdresse"
    android:ems="10"
    android:gravity="right"
    android:hint="@string/input_snm"
    android:imeActionLabel="@string/Button_berechnen"
    android:imeOptions="actionDone|flagNoExtractUi"
    android:inputType="phone"
    android:paddingRight="@dimen/padding_small"
    android:textSize="@dimen/fontsize_medium" />


Image: EditText
Image: EditText

Ok, I think it's an System error, isn't it?

3条回答
对你真心纯属浪费
2楼-- · 2020-02-07 02:26

You can use like this:

if (your_edittext.getText().length() > 0 ) {
    your_edittext.setSelection(your_edittext.getText().length());
}

Can you add this line to your EditText xml

android:gravity="right"
android:ellipsize="end"
android:paddingLeft="10dp"//you set this as you need

But when any Text writing you should set the paddingleft to zero

you should use this on addTextChangedListener

查看更多
何必那么认真
3楼-- · 2020-02-07 02:32

This works for me.

textview.setTextDirection(View.TEXT_DIRECTION_RTL);

查看更多
\"骚年 ilove
4楼-- · 2020-02-07 02:35

Set the android:Theme.Light style on the activity (theme) and android:gravity="right".

查看更多
登录 后发表回答