如何将光标设置在右侧(EditText)? [英] How to set the cursor to the right (EditText)?
问题描述
如何使用右对齐和提示文本将光标设置在右侧?
可能吗?
How to set the cursor to the right with right align and hint text?
Is it possible?
我有一个 AutoCompleteTextView 和一个带有文本右对齐和提示文本的 EditText.现在,如果其中一个被聚焦,则光标位于提示之前而不是行尾.所以现在看起来很糟糕...
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" />
图片:EditText
好的,我认为是系统错误,不是吗?
Image: EditText
Ok, I think it's an System error, isn't it?
推荐答案
你可以这样使用:
if (your_edittext.getText().length() > 0 ) {
your_edittext.setSelection(your_edittext.getText().length());
}
你能将此行添加到你的 EditText
xml
Can you add this line to your EditText
xml
android:gravity="right"
android:ellipsize="end"
android:paddingLeft="10dp"//you set this as you need
但是当任何文本写入时,您应该将 paddingleft 设置为零
But when any Text writing you should set the paddingleft to zero
你应该在 addTextChangedListener
这篇关于如何将光标设置在右侧(EditText)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!