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"/>
This one works fine for me
android:textAlignment="viewStart"
The hint direction will be at the correct side
Use Gravity Attribute to Adjust the Hint for EditText
<EditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="كلمة المرور"
android:textColorHint="#FFFFFF"
android:gravity="right"
android:inputType="textPassword"
android:background="@null"
android:textColor="#FFFFFF"
android:textSize="20dp"/>
For AppCompatEditText edit text gravity start worked for me
<androidx.appcompat.widget.AppCompatEditText
......
android:hint="كلمه السر"
android:inputType="textPassword"
android:gravity="start"
.............../>
This will work only above api 16
you can also try, Where you must have stored your current language I used this library com.akexorcist:localizationactivity
if(currentLanguage.country.toLowerCase() == "arabic"){
etPassword.gravity = GravityCompat.END
}else{
etPassword.gravity = GravityCompat.START
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With