在安卓工作室中,显示语言的问题可以通过以下代码示例来解决:
Locale sysLocale = getResources().getConfiguration().locale;
String language = sysLocale.getLanguage();
// 设置语言为英文
Locale locale = new Locale("en");
Resources resources = getResources();
Configuration config = resources.getConfiguration();
config.setLocale(locale);
resources.updateConfiguration(config, resources.getDisplayMetrics());
Intent intent = getIntent();
finish();
startActivity(intent);
注意:以上示例假设应用程序支持多语言,并且在res文件夹下有相应的字符串资源文件(如values-en/strings.xml)来存储不同语言的文本。另外,更改语言设置后,需要重启应用程序才能使设置生效。
下一篇:安卓工作室XXX不停地停止。