Can you make an EditText input from right to left?

两盒软妹~` 提交于 2019-11-29 13:37:38

It sounds like you just need to set gravity to the right.

Add this to your editText

        android:textDirection="rtl"

Just use this:

android:layout_gravity="start"
android:textAlignment="viewStart"
Silambarasan

try this code

//initialize
EditText userName = (EditText)findViewById(R.id.userName);

//set gravity for userName 
userName.setGravity(Gravity.RIGHT);

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,

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"                    

The right way is to use:

android:textAlignment="viewStart"

As it will automatically work for LTR and RTL.

Try This....

  1. Initialize User name and password fields.

    EditText username = (EditText) findViewById(R.id.username);
    
    EditText password = (EditText) findViewById(R.id.password);
    
  2. Get current Locale for RTL languages like Arabic etc,.

    String getCurrentLocale = Locale.getDefault().getDisplayLanguage();
    
  3. 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);
    
     }
    
  4. Happy coding...!

majid bhatti

try the below code

AutoCompleteTextView autoCompleteTextView = findViewById(R.id.main_searchBar);
autoCompleteTextView.setGravity(Gravity.RIGHT);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!