Change app language programmatically in Android

前端 未结 30 3764
面向向阳花
面向向阳花 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

    This is working when i press button to change text language of my TextView.(strings.xml in values-de folder)

    String languageToLoad = "de"; // your language
    Configuration config = getBaseContext().getResources().getConfiguration();
    Locale locale = new Locale(languageToLoad);
    Locale.setDefault(locale);
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
    recreate();
    

提交回复
热议问题