【问题标题】:How to set Default Cursor position to right of EditText如何将默认光标位置设置在 EditText 的右侧
【发布时间】:2014-10-10 06:09:14
【问题描述】:

我已经实现了一个 EditText,我希望文本从正确开始,我通过 set 实现了

gravity = right

但默认光标仍显示在我的文本左侧。

这是我迄今为止尝试过的:

EditText 字段的样式表代码。

<style name="_style_user_profile_editText" parent="@android:style/Widget.EditText">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_weight">1</item>
        <item name="android:textCursorDrawable">@drawable/cursor_color_blue</item>
        <item name="android:inputType">textNoSuggestions</item>
        <item name="android:gravity">right</item>
        <item name="android:singleLine">true</item>
        <item name="android:hint">e.g Joe jr.</item>
        <item name="android:background">@android:color/transparent</item>        
    </style>

我尝试使用&lt;item name="android:ellipsize"&gt;end&lt;/item&gt;,但结果保持不变.. 有什么其他建议可以将光标位置保持在正确的位置吗?

【问题讨论】:

  • 您可能想告诉我们您已经尝试过什么,您在“EditText”中究竟实现了什么,并且屏幕截图也会非常好;-)
  • 你是用android:layout_gravity还是简单的android:gravity呢?
  • 更新的问题..请看一下...thans
  • 你的 EditText 是水平 LinearLayout 吗?
  • 是的,这些 Text Label 和 EditText 的父级是 LinearLayout。

标签: android android-edittext cursor-position


【解决方案1】:

考虑这个解决方法:

使用另一个 TextView "hintView" 来显示提示文本 "e.g Joe jr."。并将 TextWatcher 添加到您的 EditText:

    et.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            // Change the hintView's visibility.
            hintView.setVisibility(TextUtils.isEmpty(s) ? View.VISIBLE : View.GONE);
        }
    });

【讨论】:

    猜你喜欢
    • 2014-04-29
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多