Search code examples
androidxmllang

Dynamic set language string source


Is it possible in Android dynamic set language string source?

Example: I have in app 2 language resources, now I need force one layout file and here I want use for example English resources but system and UI etc must stay in default language. I want only set language resources for one xml file not for whole system. Is this possible? Or any idea. Thx


Solution

  • Use this to change the language Dynamically:

    Locale locale = new Locale("en_US"); 
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    context.getApplicationContext().getResources().updateConfiguration(config, null);
    

    You can get the list of country code from here.