How to make the text direction from right to left

前端 未结 12 734
时光取名叫无心
时光取名叫无心 2020-11-29 01:00

I want to write text in (right to left language i.e. Arabic) in a TextView. But I want to make the text writing direction from right to left. gravity:rightwill

12条回答
  •  囚心锁ツ
    2020-11-29 01:42

    Another clever way which can be used in older versions of android and can be used anywhere in string so it's handier even in latest version of android, is to include the right-to-left mark or even left-to-right mark in the string when it's needed:

    left-to-right mark: ‎ or ‎ (U+200E)
    right-to-left mark: ‏ or ‏ (U+200F)
    

    This is how it's down:

    String rtl = "Hello \u200F(سلام)";
    

    The good thing about this method is you can even use it after punctuation like (,{,[,! which are positioned right incorrectly! examples:

    سلام! // wrong position
    سلام!‏ // right position by adding RLM after !
    

    look how ! is positioned correctly in second line, actually there is an RLM after it, and you can copy paste it even if it's invisible.

    The second good thing as you saw it is that you can use this method (these char codes) in any system that supports RTL like browsers, word and so on.

提交回复
热议问题