Nik*_*nde 5 android android-layout android-fragments
我正在制作一个想要在其中显示语言选择页面的页面的应用程序。到目前为止,我已将英语,北印度语和马拉地语包括在内,并将英语设置为默认值。
我的问题是:
如何在“所选语言”中更改整个应用程序语言?
选择语言之后,每当我重新打开应用程序时,它就会使用先前选择的语言?
将所有文本放入字符串文件中。为每种语言创建单独的字符串文件(德语值-de/strings.xml,法语值-fr/strings.xml),而您需要更改语言调用以下函数。对于英语语言设置“en”为另一个设置相应的键
#科特林
val config = resources.configuration
val locale = Locale("en")
Locale.setDefault(locale)
config.locale = locale
resources.updateConfiguration(config, resources.displayMetrics)
Run Code Online (Sandbox Code Playgroud)
#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());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4256 次 |
| 最近记录: |