admin管理员组文章数量:1221753
I can change the language locale on my Galaxy S23 Ultra, but when I try on my Galaxy A14 5g, the language remains the same. They are both running Android 14. I don't understand what I am doing wrong. Here is the code I am using:
String languageToLoad = "es";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
MainActivity.this.getResources().updateConfiguration(config, MainActivity.this.getResources().getDisplayMetrics());
Intent intent = new Intent(MainActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
I've tried changing the xml
string file name. It is currently values-es
. I've tried changing the bundle language enableSplit
to false
. These did not work what can I do differently?
I can change the language locale on my Galaxy S23 Ultra, but when I try on my Galaxy A14 5g, the language remains the same. They are both running Android 14. I don't understand what I am doing wrong. Here is the code I am using:
String languageToLoad = "es";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
MainActivity.this.getResources().updateConfiguration(config, MainActivity.this.getResources().getDisplayMetrics());
Intent intent = new Intent(MainActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
I've tried changing the xml
string file name. It is currently values-es
. I've tried changing the bundle language enableSplit
to false
. These did not work what can I do differently?
1 Answer
Reset to default 0From SDK 33 (Tiramisu), instead of using updateConfiguration the recommended way to change language is to use setApplicationLocales():
LocaleListCompat aLocale = LocaleListCompat.forLanguageTags(locale.getLanguage());
AppCompatDelegate.setApplicationLocales(aLocale);
It is worth to note that: This API should always be called after Activity.onCreate(), apart from any exceptions explicitly mentioned in this documentation.
Reference: setApplicationLocales
本文标签: javaWhy does changing the in app language work on some devices but not othersStack Overflow
版权声明:本文标题:java - Why does changing the in app language work on some devices but not others - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739346817a2159198.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论