Numbers inside TextView getting reversed when formatted in RTL

后端 未结 4 1680
清酒与你
清酒与你 2021-02-10 17:04

Numbers inside TextView are getting reversed when formatted in RTL. When numbers are at the end of a text inside a TextView they getting reversed. How

相关标签:
4条回答
  • 2021-02-10 17:23

    Try this out

    android:supportsRtl="false" in manifest file

    and android:gravity="start" in your layout.

    0 讨论(0)
  • 2021-02-10 17:26

    set the textview gravity to start

    android:gravity="start"
    
    0 讨论(0)
  • 2021-02-10 17:33

    If you want to prevent the reversing of numbers for TextView when formatted in RTL, just specify android:textDirection="ltr" property for that specific TextView inside XML file. It will display number in the usual order.

    0 讨论(0)
  • 2021-02-10 17:45

    The misunderstand: Digits in RTL languages like ARABIC should be written from RTL with the arabic digits to avoid any problems i.e: "تم إرسال رسالة نصية للرقم ١٢٣٤" Note that I wrote "رسالة نصية" NOT "SMS رسالة".

    The problem and it's solution: Mixing more than one direction languages required more steps, you need to tell the system "hey this is RTL word, add as it to sequence". So you may need to do this implicitly, i.e:

    \u200f + تم إرسال رسالة نصية إلى + number

    Consider StringBuilder: It's very painful for developer to develop something for RTL language using plus(+) notation, this much confusing and error prone.

    A better way:

    builder.append("\u061C").append(" تم إرسال رسالة نصية لـ").append("\u200E").append("+0123456789")
    

    Consider BidiFormatter: Utility class for formatting text for display in a potentially opposite-directionality context without garbling

    Example:

    String text = "{0} تم إرسال رسالة نصية لـ ";
    String phone = BidiFormatter.getInstance().unicodeWrap("+961 01 234 567");
    String result = MessageFormat.format(text,phone);
    

    Now, result will be formatted properly.

    More examples on how BidiFormatter work.

    0 讨论(0)
提交回复
热议问题