如何默认光标位置设置的EditText权 [英] How to set Default Cursor position to right of EditText

查看:173
本文介绍了如何默认光标位置设置的EditText权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个EditText,我想文,开始从它是正确的,我通过设置实现

I have implemented an EditText where I wanted text to start from it's right, and I achieved by set

比重=权

但默认光标还在我的文本的左侧显示出来。

But the default cursor still shows up at the left of my text.

这是我到目前为止已经试过:

This is what I have tried so far :

和样式表code代表的EditText现场。

and style sheet code for EditText Field.

<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;项目名称=机器人:ellipsize&GT;结束&LT; /项目&GT; ,但结果仍然相同..
任何其他建议,以保持右侧光标位置?

I tried with <item name="android:ellipsize">end</item> but result remain same.. any other suggestion to keep cursor position at right?

推荐答案

考虑这种解决方法:

使用另一种的TextViewhintView显示提示文本例如乔JR。并添加TextWatcher到您的EditText:

Use another TextView "hintView" to show the hint text "e.g Joe jr.". And add a TextWatcher to your 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);
        }
    });

这篇关于如何默认光标位置设置的EditText权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆