我正在制作一个应用程序,我希望在其中有一个显示语言选择页面的页面。到目前为止,我已经包括了英语、印地语和马拉地语,并将英语设置为默认值。
我的问题是:
如何在所选语言中更改整个应用程序的语言?
选择语言后,每当我重新打开应用程序时,它都会提供之前选择的语言吗?
将所有文本放入字符串文件中。为每种语言创建单独的字符串文件(德语values-de/strings.xml、法语values-fr/strings.xml)
当您需要更改语言时,请调用以下函数。对于英语语言设置"en"为另一组相应的键
#Kotlin
val config = resources.configuration
val locale = Locale("en")
Locale.setDefault(locale)
config.locale = locale
resources.updateConfiguration(config, resources.displayMetrics)
#Android Java
Configuration config = getBaseContext().getResources().getConfiguration();
Locale locale = new Locale("en");
Locale.setDefault(locale);
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)