1

How to make EditText Hint right to left -sided

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

Maher Ismaail
  • 1,663
  • 2
  • 15
  • 26

4 Answers4

9

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

ketan
  • 19,129
  • 42
  • 60
  • 98
Prashant
  • 138
  • 7
9

try to use attributes

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

It works for me

Jackky777
  • 644
  • 12
  • 19
1

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

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" />
Zelalem
  • 392
  • 5
  • 7
  • Well if I understood your question clearly, you are looking for the EditText container layout to be from right to left, in that case you can change the layout width and check. The above answer I gave you works for me. But if you are looking for the end of the screen layout, you can change it using: android:layout_gravity="end". – Zelalem May 26 '15 at 05:48