问题
I was wondering if you can control input on an EditText to move from right to left? The EditText would have to support insert/delete etc. from right to left as well. Is there a way to do this?
回答1:
It sounds like you just need to set gravity to the right.
回答2:
Add this to your editText
android:textDirection="rtl"
回答3:
Just use this:
android:layout_gravity="start"
android:textAlignment="viewStart"
回答4:
try this code
//initialize
EditText userName = (EditText)findViewById(R.id.userName);
//set gravity for userName
userName.setGravity(Gravity.RIGHT);
回答5:
The right way is to use:
android:textAlignment="viewStart"
As it will automatically work for LTR and RTL.
回答6:
There is the manual way to do it by using the following code :
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
// Each time click Menu button on the bar
// Set the cursor to the first index
mEtEmail.setSelection(0); // YOUR EDIT TEXT
}
return super.onKeyUp(keyCode, event);
}
p/s : Or you can change
KeyEvent.KEYCODE_MENU
follow your wishes,
Or you can try with Bidi.
Thanks,
回答7:
you can add to your edittext in xml:
in case of left to right :
android:textDirection="firstStrongLtr"
in case of right to left :
android:textDirection="firstStrongRtl"
回答8:
Try This....
Initialize User name and password fields.
EditText username = (EditText) findViewById(R.id.username); EditText password = (EditText) findViewById(R.id.password);Get current Locale for RTL languages like Arabic etc,.
String getCurrentLocale = Locale.getDefault().getDisplayLanguage();Then we should check which language is selected for RTL or LTR.
if(getCurrentLocale.equalEgnoreCase("English")){ //LTR languages username.setGravity(Gravity.Left); password.setGravity(Gravity.Left); }else{ //RTL languages username.setGravity(Gravity.Right); password.setGravity(Gravity.Right); }Happy coding...!
回答9:
try the below code
AutoCompleteTextView autoCompleteTextView = findViewById(R.id.main_searchBar);
autoCompleteTextView.setGravity(Gravity.RIGHT);
来源:https://stackoverflow.com/questions/5083768/can-you-make-an-edittext-input-from-right-to-left