如何更改整个应用程序语言? [英] How to change the whole application language?
问题描述
我正在制作一个想要在其中显示语言选择页面的页面的应用程序.到目前为止,我已将英语,北印度语和马拉地语包括在内,并且将英语设置为默认语言.
I am making an app in which I want to have a page where I show a language selection page. So far I've included English, Hindi, and Marat with English set as the default.
我的问题是:
-
如何在所选语言"中更改整个应用程序语言?
how to change the whole application language in Selected Language?
选择语言之后,只要我重新打开应用程序,它就会使用先前选择的语言?
After choose the language whenever I reopen the application its give previous chosen language?
推荐答案
将所有文本放入String文件.为每种语言创建单独的字符串文件(Deutsch values-de/strings.xml,法语values-fr/strings.xml) 并且当您需要更改语言调用跟踪功能时.对于英语,为另一组对应的键设置"en"
Put your all text in String file. For each language create separate String file(Deutsch values-de/strings.xml, French values-fr/strings.xml) and while you need to change language call following function. For English language set "en" for another set corresponding key
#Kotlin
val config = resources.configuration
val locale = Locale("en")
Locale.setDefault(locale)
config.locale = locale
resources.updateConfiguration(config, resources.displayMetrics)
#Android Java
#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());
这篇关于如何更改整个应用程序语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!