I have a multilingual app with primary language English and secondary language Arabic.
As described in the documentation,
- I have added
android:supportsRtl="true"
in the manifest. - I have changed all xml properties with
left
andright
attributes tostart
andend
respectively. - I have added Arabic language strings in
strings-ar
(and similarly for other resources).
The above setup works properly. After changing the Locale
to ar-AE
, Arabic text & resources are correctly displayed in my Activities.
However, every time I navigate to an
Activity
with aWebView
and/or aWebViewClient
, the locale, text and layout direction abruptly revert to the device default.
Further hints:
- This is occurring only on a Nexus 6P with Android 7.0. Everything works properly on Android 6.0.1 and below.
- The abrupt shift in locale happens only when I navigate to an
Activity
that has aWebView
and/or aWebViewClient
(and I have several). It does not occur on any of the other Activities.
Android 7.0 has multi-locale support, allowing the user to set more than one default locale. So if I set the primary locale to Locale.UK
:
Then on navigating to the
WebView
, the locale changes fromar-AE
toen-GB
.
Android 7.0 API changes:
As indicated in the list of API changes, new methods pertaining to locale have been added to the following classes in API 24:
Locale
:
Configuration
:
However, I am building my app with API 23, and am not using any of these new methods.
Furthermore ...
The problem occurs on the Nexus 6P emulator as well.
To get the default locale, I am using
Locale.getDefault()
.To set the default locale, I am using the following code:
public static void setLocale(Locale locale){ Locale.setDefault(locale); Configuration config = new Configuration(); config.setLocale(locale); Context context = MyApplication.getInstance(); context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); }
Has anyone encountered this problem before? What is the reason for it, and how do I resolve this?
References:
1. Native RTL support in Android 4.2.
onCreate
(or other relevant code) of the activity that inflates or instantiates the webview? – Loginov