【问题标题】:How to set the cursor to the right (EditText)?如何将光标设置在右侧(EditText)?
【发布时间】:2014-04-29 01:38:19
【问题描述】:

如何通过右对齐和提示文本将光标设置在右侧?
有可能吗?

我有一个 AutoCompleteTextView 和一个带有文本右对齐和提示文本的 EditText。 现在,如果其中一个被聚焦,则光标在提示之前而不是在行尾。 所以看起来现在很糟糕......

我也尝试过设置光标位置,但当然没有帮助。

<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


好的,我认为这是系统错误,不是吗?

【问题讨论】:

  • 你能看到我的回答吗

标签: android android-edittext autocompletetextview


【解决方案1】:

你可以这样使用:

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

你能把这行添加到你的EditText xml

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

但是当任何文本写入时,你应该将 paddingleft 设置为零

你应该在addTextChangedListener上使用它

【讨论】:

  • 你是否使用了 if(cm.getActiveNetworkInfo.Gettext() >0) then Set cursor
  • 我什至在 4.0.3 上尝试过 - 它可以工作,但在 4.1.2 (S3 Stock & PA) 上无效
  • 我的意思是 Set 选择方法你是什么时候使用 if 控件的,当你使用 setselection 时的错误是什么
  • 我编辑我的答案,如果它给出错误请显示错误
  • 所以我认为有一种方法,而不是提示您将文本设置为电子邮件并赋予文本颜色,它看起来像提示并且光标在最后,当 Ã Text Enter 您应该首先删除 Text 并更改文字颜色,这解决了你的问题
【解决方案2】:

这对我有用。

textview.setTextDirection(View.TEXT_DIRECTION_RTL);

【讨论】:

    【解决方案3】:

    在活动(主题)和android:gravity="right"上设置android:Theme.Light样式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-10
      • 1970-01-01
      • 1970-01-01
      • 2019-12-28
      • 2011-11-06
      • 1970-01-01
      • 2015-03-29
      相关资源
      最近更新 更多