0

I change the language at my own application settings. How can I directly load the new language in the settings activty.

I find out the solution to go too an other activity and than the language is changed. I want it earlier

The Code where I change the language:

SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String language =SP.getString("language", "en");
android.content.res.Configuration config = new android.content.res.Configuration();
config.locale = new Locale(language);
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());

my onConfigurationChanged Method:

  @Override
public void onConfigurationChanged(Configuration locale) {
    super.onConfigurationChanged(locale);
    Toast.makeText(settings.this, "test", Toast.LENGTH_SHORT).show();

    SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    String language =SP.getString("language", "en");
    android.content.res.Configuration config = new android.content.res.Configuration();
    config.locale = new Locale(language);
    getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
ketan
  • 19,129
  • 42
  • 60
  • 98
Bukmop
  • 37
  • 5
  • 2
    You need to implement `onConfigurationChanged` - see: http://developer.android.com/reference/android/app/Activity.html#onConfigurationChanged(android.content.res.Configuration) Then "re-set" your texts. – Darwind Mar 01 '16 at 11:24
  • i add the onConfiguartionChanged at the settings class where my Preferencefragment is loaded. But the app doesn't go in at AndoridManifest I add: android:configChanges="layoutDirection|locale" – Bukmop Mar 01 '16 at 12:48
  • Show me how your `onConfigurationChanged` method looks like. This is where you need to re-set your texts again. – Darwind Mar 01 '16 at 12:56
  • I just realised I answered another question close to yours here: http://stackoverflow.com/questions/18365354/locale-onconfigurationchanged-not-called/18390027#18390027 - Also see: http://snowpard-android.blogspot.dk/2013/03/programmatically-change-language-in.html for how to implement this completely. – Darwind Mar 01 '16 at 13:32
  • Ok. I add a button in the activtiy. If i push this the settings would be reload. In my opinion it's not the best solution, because i want have settings reload if something changed there, but it is a solution Thanks all – Bukmop Mar 02 '16 at 07:15
  • you have to make separate file of string in values folder. then when user change his language setting for then your application automatically change it's language also.for this you can see this. http://developer.android.com/training/basics/supporting-devices/languages.html – Bhunnu Baba Mar 29 '16 at 04:47

0 Answers0