Can you make an EditText input from right to left?

后端 未结 10 1227
天命终不由人
天命终不由人 2020-12-20 11:52

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 th

10条回答
  •  星月不相逢
    2020-12-20 12:32

    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...!

提交回复
热议问题