Change app language programmatically in Android

前端 未结 30 2965
面向向阳花
面向向阳花 2020-11-21 04:34

Is it possible to change the language of an app programmatically while still using Android resources?

If not, is it possible to request a resource in an specific lan

30条回答
  •  广开言路
    2020-11-21 05:12

    Locale locale = new Locale("en");
    Locale.setDefault(locale);
    
    Configuration config = context.getResources().getConfiguration();
    config.setLocale(locale);
    context.createConfigurationContext(config);
    

    Important update:

    context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
    

    Note, that on SDK >= 21, you need to call 'Resources.updateConfiguration()', otherwise resources will not be updated.

提交回复
热议问题