Localize an Android application so that I can switch the locale inside the application

How to localize an application so that it uses a specific locale no matter what language is installed on the device? I want users to be able to choose the language of their choice.

So far, I have this code in my Application class:

@Override public void onCreate() { //Set locale String l = Preferences.getLocale(getApplicationContext()); if (!l.equals("")) { Locale locale = new Locale(l); Locale.setDefault(locale); Configuration config = getBaseContext().getResources().getConfiguration(); config.locale = locale; getBaseContext().getResources().updateConfiguration( config, getBaseContext().getResources().getDisplayMetrics()); } LogData.InsertMessage(getApplicationContext(), "Application started"); } 

The problem that I have is that it seems that I'm showing in set locale just fine (TextViews) But the subtitles and menu toasts will fall by default.

Is there any 1-2-3 on how to make it work correctly? I am using version 2.2

+4
source share
2 answers

This post explains how to force localization in your application.

+5
source

Well, I understood why I had this problem. I had to override onConfigurationChanged in my application class. This is a much more elegant solution than specifying the locale on each Activity .

+1
source

All Articles