1

using the following resource:

ltr: <string name="err_field_range_hint_f">Possible values: [%1$.0f .. %2$.0f]</string> 
rtl: <string name="err_field_range_hint_f">ערכים אפשריים:
   [%2$.0f .. %1$.0f]</string>  

in the following code:

 _AlertDialog = new AlertDialog.Builder(this).
  setTitle(getString(R.string.title))                             
  .setMessage(getString(R.string.err_field_range_hint_f, valLow, valHigh) ) 
  .setPositiveButton(getString(R.string.ok), null)
  .show();

I receive [25- .. 100] instead of [-25 .. 100]

I solved similiar problem in the layout with forcing LTR in EditText fields, using:

android:inputType="numberSigned|numberDecimal" 
android:textDirection="ltr"

but how can I force LTR on specific "words" (or numbers) inside AlertDialog.Message?

Note: I saw a solution in here but I prefer android would handle formatting numbers...

Tanveer Munir
  • 1,936
  • 1
  • 10
  • 25
Atara
  • 3,335
  • 5
  • 34
  • 52

2 Answers2

2

I am not sure you want to receive

enter image description here

and not

enter image description here

At any rate, the easiest fix is to insert the Unicode BIDI override markers, e.g. LRO:

<string name="err_field_range_hint_f">ערכים אפשריים:
    \u202D[%2$.0f .. %1$.0f]\u202C;</string>  
Alex Cohn
  • 52,705
  • 8
  • 94
  • 269
  • what is the difference between \u202D, \u202C vs. U+200E, U+200F ? https://stackoverflow.com/a/30415888/262923 – Atara Mar 07 '19 at 12:45
  • If you ask about **\uXXXX** vs. **U+XXXX** – these are simply different notations. The former is supported in Android XML. Maybe you can use other notations, too. – Alex Cohn Mar 07 '19 at 14:27
  • As for the behaviour of different Unicode markers, *Left-to-Right Mark* (LRM) **\u200E** is an invisible character that is equivalent to letter **A**. It does not change the 'paragraph order', or `android:textDirection` of the text field. The LRO character starts a 'span' that is almost like `android:textDirection="ltr"` within the text field. – Alex Cohn Mar 07 '19 at 15:11
1

You can find the "message" text view inside the alert dialog, and than apply the same method you used on your edit text to correct the LTR issue.

Consider this SO answer to find the inner text view:

https://stackoverflow.com/a/35808187/3339597

Re'em
  • 1,311
  • 1
  • 17
  • 24
  • can I split the inner message into few text views? "ערכים אפשריים:" is RTL but "[%2$.0f .. %1$.0f]" is LTR ? – Atara Mar 07 '19 at 08:36
  • I'm not aware of any method to split text behaviour in a single text view. You can create your own custom dialog with multiple text views, one for each segment. To create a custom dialog visit here: https://stackoverflow.com/q/13341560/3339597 – Re'em Mar 07 '19 at 08:49