Skip to content Skip to sidebar Skip to footer

Set-up The Application Language In Android Preferences

I would like the application language to be set according to the user preferences but up till now it doesn't work how I would like it to. I have set the default values: strings.xml

Solution 1:

OK it may help someone. I have added the folowing to the main activity manifest:

android:configChanges="locale"

Then when the user choses the preferences I have put a confirm button and then this button brings you to main activity that is why the lnagages gets reset.

I have a static class where I have this code to change the locale:

publicstaticvoidupdateLanguage(Context context, String idioma) {
    if (!"".equals(idioma)) {
        if ("castella".equals(idioma)) {
            idioma = "es_ES";
        } elseif ("catala".equals(idioma)) {
            idioma = "ca_ES";
        }
        Locale locale = new Locale(idioma);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        context.getResources().updateConfiguration(config, null);
    }
}

end at every activity I have like 20 of them I call this method before:

setContentView(R.layout.list_event);

With these methods when I rotate the screen the activities don't change the language here is a link to a blog that helped me: http://adrianvintu.com/blogengine/post/Force-Locale-on-Android.aspx

Solution 2:

I would think that you need to be setting the locale in the MainActivity onCreate method. The same way you are setting it when the onSharedPreferenceChanged method.

Post a Comment for "Set-up The Application Language In Android Preferences"