Friday, 7 September 2018

Resources and RTL layouts rendered incorrectly on Oreo and above

There is a problem with both resources and RTL layouts for all Android devices with version 8.0 and above.

I am calling the following method in the onCreate() of my BaseActivity (from which every Activity in my app is derived):

public static void setLocale(Locale locale){
    Locale.setDefault(locale);
    Context context = MusafirApplication.getInstance();
    final Resources resources = context.getResources();
    final Configuration config = resources.getConfiguration();
    config.setLocale(locale);
    context.getResources().updateConfiguration(config,
            resources.getDisplayMetrics());
}

where locale is one of the following:

enter image description here

The above method is called before super.onCreate(savedInstanceState) gets called.

I have put Arabic-language strings in res\values-ar\strings folder and drawable resources in res\drawable-ar folder.

On a device with version less than 8.0, an RTL screen correctly looks like this:

enter image description here

And on all devices with 8.0+, the same screen turns up looking like this:

enter image description here

which is wrong.

It turns out that both the direction and the resources are getting loaded incorrectly.

Surprisingly, this problem does not seem to be talked about much, despite its seriousness. This has been reported only once on SO in the entire year since Android 8.0 has been released:

RTL layout bug in android Oreo

The solutions provided are not really working for me. I would like to know what this problem is, why it happens in Oreo and what is the solution for it. Please help / comment on this.



from Resources and RTL layouts rendered incorrectly on Oreo and above

No comments:

Post a Comment