I'm working on and activity with arabic language. I want the hint of the username and password to start from the right and I have no problem f typing started from the left but in my UI I want the hint to be of the right side. But when I'm adding the inputType for the EditText the hint moves to the left.I tried solving it programmatically but it didn't work.
Java
EditText password = (EditText) findViewById(R.id.input_password);
password.setTypeface(Typeface.DEFAULT);
XML
<EditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="كلمة المرور"
android:textColorHint="#FFFFFF"
android:inputType="textPassword"
android:background="@null"
android:textColor="#FFFFFF"
android:textSize="20dp"/>
add gravity
right
try this wayif your API level 17 and higher you can use
I think you can fix it by adding
\u202B
to the Hebrew/Arabic (or any other RTL language) text .Example:
Sadly it seems it doesn't get shown on the layout preview, but it worked for me on a real device. Wrote about it here
Use Gravity Attribute to Adjust the Hint for EditText
Use 'gravity' attribute:
This is a bug in the Android Framework, for EditText fields in Android 4.4+ : https://code.google.com/p/android/issues/detail?id=201471. As of July 2016, it is currently unsolved.
However there is a way to workaround it:
To make the hint display properly on the right (in right-to-left/RTL mode), you must remove the InputType property
textPassword
(InputType.TYPE_TEXT_VARIATION_PASSWORD
), when there is no text entered.To retain the password entry field behaviour of showing dots to conceal typed text, you must dynamically enable
InputType.TYPE_TEXT_VARIATION_PASSWORD
, when the first character is entered in. And it must be reset when all characters are deleted.To prevent the UI glitch of Latin character input (LTR text like "abc123") jumping to the left or disappearing altogether, you must explicitly set textDirection to RTL.
Here are the details:
Pre-requisite for your
AndroidManifest.xml
:Your XML Layout contains:
Java code with workaround bug fix: