Reputation: 193
I'm trying to make EditText
with a hint text:
In English "password" .. the cursor is correctly set to the left.
But for Arabic for which the hint is "كلمه المرور" the cursor is always set to the left (the end of the hint) instead of the right.
<EditText
android:id="@id/ETPass"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/etUsrName"
android:layout_marginLeft="@dimen/_25sdp"
android:layout_marginRight="@dimen/_25sdp"
android:layout_marginTop="@dimen/_5sdp"
android:background="@drawable/signup_edittext_input"
android:ellipsize="start"
android:gravity="center|right"
android:hint="@string/Password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:paddingRight="@dimen/_5sdp"
android:singleLine="true"
android:textColor="@color/orange"
android:textColorHint="@color/orange" />
This happens only for android:inputType="textPassword"
. Everything works fine for a normal text inputType
.
Upvotes: 6
Views: 2996
Reputation: 3642
Maybe I am late, but I faced the same issue. I resolved the issue with the following workaround.
// Get Current language
public static String getCurrentLanguage(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getString(CURRENT_LANGUAGE, "");
}
// Check if the language is RTL
public static boolean isRTL(String locale) {
return TextUtilsCompat.getLayoutDirectionFromLocale(new Locale(locale)) == ViewCompat.LAYOUT_DIRECTION_RTL ? true : false;
}
// Set gravity to the right
private void repositionPasswordTextInArabic(){
if( LocaleSettings.isRTL(LocaleSettings.getCurrentLanguage(this))){
password.setGravity(Gravity.RIGHT);
}
}
Upvotes: 0
Reputation: 1391
Use both, to resolve the alignment issue (even in Samsung device also)
android:textAlignment="viewStart"
android:textDirection="rtl"
Upvotes: 0
Reputation: 2386
For Android 17 and higher(4.2.+) its working:
android:textAlignment="viewStart"
Upvotes: 5
Reputation: 180
xml code
<EditText
android:maxLength="@integer/lockMaxLen"
android:inputType="textPassword"
android:layout_width="180dip"
android:gravity="right|center"
android:hint="@string/lock_pass_hint"
android:layout_height="45dip"
android:id="@+id/lockPassword" />
in oncreate
passwordEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence currentDigits, int start,
int before, int count) {
if (passwordEditText.getText().toString().length() == 0)
passwordEditText.setGravity(Gravity.RIGHT);
else
passwordEditText.setGravity(Gravity.LEFT);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
Upvotes: 0