I have made 2 different strings.xml, 1 for swedish and 1 for english.
Code for changing Locale
public void setLocale(String lang) {
Locale myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(getContext(), BaseActivity.class);
startActivity(refresh);
}
Onclicklisteners for switching language
swedish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setLocale("sv");
}
});
english.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setLocale("en");
}
});
The thing is, the app took it by itself to start the app on swedish, which, as far as I know, haven't set by myself. How do I change the default Locale when the app starts?
Question
- How do I set the app to start with using the english xml?
- Does anyone have a tip on how to store the choice the user makes? I want it to store if the user presses to use swedish if it closes the app.
values-sw
andvalues-en
and put differentstrings.xml
file in to them. – Piyush