I am stuck up in a problem since last few days. I am creating an application for a worldwide release for which the strings will come from server side means dynamic localisation and as we all know that we can not modify strings.xml during runtime. So is there a method to achieve this?
Asked
Active
Viewed 253 times
2 Answers
0
You can set the locale programatically at some point in your application.
Possibly at the beginning e.g the onCreate() method of your Base Activity
A similar question has been asked before: Set Locale programmatically
As noted from the "reporter's comment below:
Locale locale = new Locale("ru");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());

Community
- 1
- 1

AndroidEnthusiast
- 6,557
- 10
- 42
- 56
0
Create a method to change language:
private void setLocale (String localeCode , Bundle b)
{
locale = new Locale(localeCode);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
getApplicationContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
UserDetail.this.getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
onCreate(null);
}
And call the function:
setLocale("en-us",savedInstanceStat); // English

extmkv
- 1,991
- 1
- 18
- 36
-
1I have already mentioned it in the question tht it is impossible to change string.xml at runtime. – Rishabh Srivastava Oct 04 '14 at 09:30