I can not solve the problem with "writing text from right to left." I need such a thing for a binary calculator, which is needed on one of the screens) I saw this rtl tag - but it does not work. In the English part of the stack, everyone talks about gravity = "right", but that did not help either. I am one step away from a private self-made solution of this problem) Tell me how to write text in TextEdit from right to left !?

P / S / EditText is wrapped in Constarint Layout if it matters.

  • one
    What is your API? rtl c 17+ - Timur Mukhortov
  • one
  • this is just what you need) I’ll finish it a bit and in general there will be fire! - Georgy Chebotaryov

2 answers 2

Use the following solution:

xml:

android:textDirection="rtl" android:gravity="right" 

Programmatically:

  textview.setTextDirection(View.TEXT_DIRECTION_RTL); 

or

  textview.setTextDirection(View.TEXT_DIRECTION_ANY_RTL); 

Start with API 17+

Add text to the beginning of the textView :

 textview.setText(number + textView.getText()); 
  • I tried it - it does not work. Perhaps you know what can block his work? - Georgy Chebotarev
  • one
    What is the minimum version of the android in gradle? - Timur Mukhortov
  • 21 or 23. I use Constraint Layout for item. Based on the item, a recyclerView is created. If this helps, I can give the code of a particular file. - George Chebotaryov
  • one
    Hmm, but programmatically tried to do? - Timur Mukhortov
  • one
    try, I corrected the answer, added the program method - Timur Mukhortov

I decided to add my total version to Kotlin. This code allows you to write text from right to left that each next character appears to the left of the cursor. The usual textdirection does not give the effect of "Arabic writing"

  editText.addTextChangedListener(object : TextWatcher { override fun afterTextChanged(s: Editable) { } override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { } override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { // set cursor editText.setSelection(start) } })