1

I have an app that supports Hebrew and declares in the manifest its support for RTL locales. However, there are other RTL locales that I do not support and would like my Views not to be mirrored when these locales are set. For example, I don't want my app's Views to be swapped from right to left when in the Arabic locale, since I don't support Arabic and therefore text will show in English.

j0k
  • 22,600
  • 28
  • 79
  • 90
AxiomaticNexus
  • 6,190
  • 3
  • 41
  • 61

2 Answers2

6

I guess the best way is to make android:supportsRtl value to be selected according to the language. To do that see below:

AndroidManifest.xml

 <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:supportsRtl="@string/is_hebrew" >...</application>

Then in values/strings.xml add:

<string name="is_hebrew">false</string>

And with values-he/strings.xml add:

<string name="is_hebrew">true</string>
xsoh
  • 419
  • 3
  • 11
  • 1
    This is pretty clever, but does not work to perfection. Apparently the system reads the manifest file only once, either when the app is installed, or first run. This means that if you install the app while the phone is in English, run it and then change the phone's language to Hebrew, the app will be stuck with the left-to-right layout. You would have to reinstall the app with the phone in Hebrew in order to have it change to the right-to-left layout. – AxiomaticNexus Mar 21 '14 at 19:19
  • Have you killed the app after changing the language? I've did a testing version and it worked for me very well. see here: https://dl.dropboxusercontent.com/u/4172185/testStackoverflow.tar.gz – xsoh Mar 21 '14 at 22:42
  • Can you put that in a zip file? I'm on Windows and don't have privileges to install software to open that file. And yes, I killed the app, but still will not change until you uninstall the whole thing. – AxiomaticNexus Mar 21 '14 at 22:47
  • Here(Note: I did the same idea but with Arabic language): https://dl.dropboxusercontent.com/u/4172185/testStackoverflow.zip – xsoh Mar 21 '14 at 22:53
  • Nope. Doesn't work. Here's what I did: 1- Install the app with an emulator in the English locale. 2- Open the app. 3- Change the emulator's locale to Arabic. 4- Reopen the app. 5- The app's layout is still left-to-right. – AxiomaticNexus Mar 21 '14 at 23:20
  • 1
    I guess there is a problem with the older versions of the platform. I've tried it on Kitkat (4.4.2) and it was working very well. But on JB(API 18) didn't work. Note: I'm changing the language thought Settings not Custom Locale. – xsoh Mar 22 '14 at 08:57
3

You can choose to turn mirroring on or off at runtime. See https://stackoverflow.com/a/17683045/192373. This is limited to 4.2 or higher, and only in onCreate() of your activity.

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307