xml - Android App locale changes back to English on Theme Change - Stack Overflow

admin2025-04-17  3

Summary: When the theme is changed on the Select a Language, History, and Change App Language screens, the titles switch from the selected language to English, causing inconsistency in the language settings. Steps to Reproduce: Open the app and set the language to a non-English language (e.g., Spanish, French, etc.). Navigate to any of the following screens: Select a Language History Change App Language Change the theme (e.g., switch between light and dark mode). Observe that the titles on these screens change from the selected language to English after the theme changed.

 private void updateLocale(String langCode) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
            LocaleListCompat appLocale = LocaleListCompat.forLanguageTags(langCode);
            AppCompatDelegate.setApplicationLocales(appLocale);
        } else {
            Locale locale = new Locale(langCode);
            Locale.setDefault(locale);
            Configuration config = new Configuration();
            config.setLocale(locale);
         getResources().updateConfiguration(config,getResources().getDisplayMetrics());
        }
    }
转载请注明原文地址:http://anycun.com/QandA/1744879469a88919.html