In my application which supports 2 languages English and Arabic, the below code is used to set the locale for the selected language. Both LTR and RTL layouts work fine with all the devices except the Xiaomi, Redmi devices. In the Xiaomi devices, the RTL layout is not working.
//main method
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return updateResources(context, "ar"); // for English "en"
}
//Code
private static Context updateResources(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Configuration configuration = context.getResources().getConfiguration();
configuration.setLocale(locale);
configuration.setLayoutDirection(locale);
return context.createConfigurationContext(configuration);
}