问题描述
我希望用户在应用程序内选择一种语言.选择语言后,我希望字符串使用特定的语言.
I want user to select a language inside the app. Once the language is selected, I want the strings to use the particular language.
如果我更改电话语言,则我的应用将以设置的语言运行.
If I change the phone language, then my app runs on the set language.
在不更改电话语言的情况下,我无法找到任何一种设置语言的方法.此外,一旦设置了语言,更改就应该反映出来.
I am not able to find any way to set a language without changing the phone language. In addition, the changes should be reflected once the language is set.
有人可以建议一种方法吗?
Could anyone please suggest a way to do it?
推荐答案
尝试一下
public static void changeLang(Context context, String lang) {
Locale myLocale = new Locale(lang);
Locale.setDefault(myLocale);
android.content.res.Configuration config = new android.content.res.Configuration();
config.locale = myLocale;
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
}
对于英语,语言参数应为"en",对于意大利语,参数应为"it" ...之后,您应重新启动活动/片段
Lang parameter should be "en" for English, "it" for Italian... After that you should restart your activity/fragment
这篇关于如何在不更改手机语言的情况下更改android应用语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!