Search code examples
androidright-to-left

negative number within RTL AlertDialog


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


Solution

  • 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>