How to set default cursor position to the right of EditText

I implemented EditText where I wanted the text to start with it correctly, and I achieved with set

gravity = right

But the default cursor is still displayed to the left of my text.

This is what I have tried so far:

enter image description here

and style sheet code for the 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>

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

0
source share
1 answer

Consider this workaround:

Use another textual “hintView” to display the prompt text “for example, 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 visibility.
            hintView.setVisibility(TextUtils.isEmpty(s) ? View.VISIBLE : View.GONE);
        }
    });
0
source

Source: https://habr.com/ru/post/1570826/


All Articles