我正在尝试使用提示文字制作EditText
:
用英文“password”..光标正确设置在左侧。
但对于提示为“كلمهالمرور”的阿拉伯语,光标始终设置为左侧(提示的结尾)而不是右侧。
<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" />
这仅适用于android:inputType="textPassword"
。对于普通文本inputType
,一切正常。
答案 0 :(得分:1)
尝试:
android:textDirection="rtl"
答案 1 :(得分:1)
对于Android 17及更高版本(4.2。+)的工作:
android:textAlignment="viewStart"
答案 2 :(得分:0)
xml代码
<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" />
在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) {
}
});
答案 3 :(得分:0)
Use both, to resolve the alignment issue (even in Samsung device also)
android:textAlignment="viewStart"
android:textDirection="rtl"
答案 4 :(得分:0)
也许我来晚了,但是我遇到了同样的问题。我通过以下解决方法解决了该问题。
// 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);
}
}
答案 5 :(得分:0)
editText.setSelection(editText.getText().length());