Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hint Alignment to the right of password EditText

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"/>
like image 564
Deve Avatar asked Feb 15 '16 07:02

Deve


3 Answers

This one works fine for me

android:textAlignment="viewStart"

The hint direction will be at the correct side

like image 100
Ahmad Salman Avatar answered Oct 12 '22 01:10

Ahmad Salman


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"/>
like image 21
Veeresh Charantimath Avatar answered Oct 12 '22 00:10

Veeresh Charantimath


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
}
like image 33
Tapan Gohil Avatar answered Oct 12 '22 00:10

Tapan Gohil