Created
August 20, 2013 10:28
-
-
Save up1/6279814 to your computer and use it in GitHub Desktop.
Change Local in Android application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyApplication extends Application | |
{ | |
private Locale locale = null; | |
@Override | |
public void onConfigurationChanged(Configuration newConfig) | |
{ | |
super.onConfigurationChanged(newConfig); | |
if (locale != null) | |
{ | |
newConfig.locale = locale; | |
Locale.setDefault(locale); | |
getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics()); | |
} | |
} | |
@Override | |
public void onCreate() | |
{ | |
super.onCreate(); | |
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); | |
Configuration config = getBaseContext().getResources().getConfiguration(); | |
String lang = settings.getString(getString(R.string.pref_locale), ""); | |
if (! "".equals(lang) && ! config.locale.getLanguage().equals(lang)) | |
{ | |
locale = new Locale(lang); | |
Locale.setDefault(locale); | |
config.locale = locale; | |
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment