0

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

gravity = right

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

This is what I have tried so far :

enter image description here

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>

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

CoDe
  • 11,056
  • 14
  • 90
  • 197
  • You might want to tell us what you already tried, what you exactly implemented in your 'EditText' and a screenshot wouhld also be very nice ;-) – L.Butz Oct 10 '14 at 07:05
  • are you using `android:layout_gravity` or simple `android:gravity` for it? – Piyush Oct 10 '14 at 07:34
  • updated question ..please have a look...thans – CoDe Oct 10 '14 at 07:41
  • Is your EditText is in horizontal LinearLayout? – Piyush Oct 10 '14 at 07:42
  • yes, parent of these Text Label and EditText is LinearLayout. – CoDe Oct 10 '14 at 07:43
  • It is in right position but because of applied hind it is displaying like this ways. After you write text in edittext it simply start from right. your looks like proper. – Piyush Oct 10 '14 at 07:45
  • yes...I also checked with hint text and that's the problem I thinking...logically it's right...but is there any way to get it right in this case? – CoDe Oct 10 '14 at 07:58
  • If you just remove hint then it will be perfect at right position. And if you need compulsory hint then this is a general behaviour and may be you can change it programmatically. – Piyush Oct 10 '14 at 08:00

1 Answers1

0

Consider this workaround:

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);
        }
    });
Feng Dai
  • 633
  • 5
  • 9