Skip to content Skip to sidebar Skip to footer

How To Set Default Cursor Position To Right Of Edittext

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. Th

Solution 1:

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);
        }
    });

Post a Comment for "How To Set Default Cursor Position To Right Of Edittext"