Question

It's very easy to place different string.xml files for multiple languages like:

 English
   Values
     String.xml


Arabic   
   Values-ar
    String.xml

but it only works when device language is changed. My scenario is I have to load a user selected language in the application, different from the one selected in the device so how can I load different String.xml files?

Was it helpful?

Solution

You can change the application language using the following code:

Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());

languageToLoad is a String variable like "en" or "ar".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top