Maher Ismaail
Maher Ismaail

Reputation: 1663

How to make EditText Hint right to left -sided?

How to make EditText Hint right to left -sided

I write Arabic word hint ,, and its showing on the left side .

Upvotes: 1

Views: 6490

Answers (4)

M.Bakhshipour
M.Bakhshipour

Reputation: 51

You can use below code to resolve your problem:

        myEditText.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) {
            if (myEditText.getText().toString().length() > 0 & myEditText.getGravity() != Gravity.LEFT) {
                myEditText.setGravity(Gravity.LEFT);
            } else if (myEditText.getText().toString().length() == 0 & myEditText.getGravity() != Gravity.RIGHT) {
                myEditText.setGravity(Gravity.RIGHT);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

Upvotes: 1

Jackky777
Jackky777

Reputation: 654

try to use attributes

android:textDirection="locale"
android:textAlignment="viewStart"

It works for me

Upvotes: 9

Prashant
Prashant

Reputation: 138

Try this one: Use android:gravity="right"

Upvotes: 9

Zelalem
Zelalem

Reputation: 392

You can use android:gravity to change the position of your text in side the EditText container. Here you can find more about Gravity.

For example

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Your hint here"
    android:gravity="end"
    android:id="@+id/editText" />

Upvotes: 0

Related Questions