我怎样才能改变我的应用程序的语言? [英] How can I change language of my application?
本文介绍了我怎样才能改变我的应用程序的语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用我有语言选择的选项。
In my application I have a option of language selection.
有三种语言:英语,德语和放大器;西班牙。当我选择一个选项,整个应用程序的语言应该有所改变。
There are three languages: English, German & Spanish. When I select an option, the entire application language should be changed.
我怎样才能让这一切成为可能?
How can I make this possible?
推荐答案
你的意思是,你要使用比手机的默认语言另一种语言?我有一个应用程序,这是我必须做的。
Do you mean that you want to use another language than the default language in the phone? I have that in one application, and this is what I had to do.
这添加到您的活动声明中的的AndroidManifest.xml
Add this to your activity declaration in the AndroidManifest.xml
<activity
android:name=".ui.SomeActivity"
android:configChanges="locale"
:
:
</activity>
然后再从的onCreate
调用这样的方法,在你的活动:
And then invoke a method like this from onCreate
in your activity:
public static void setLanguage(Context context, String languageToLoad) {
Log.d(TAG, "setting language");
Locale locale = new Locale(languageToLoad); //e.g "sv"
Locale systemLocale = SystemLocale.getInstance().getCurrentLocale(context);
if (systemLocale != null && systemLocale.equals(locale)) {
Log.d(TAG, "Already correct language set");
return;
}
Locale.setDefault(locale);
android.content.res.Configuration config = new android.content.res.Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
Log.d(TAG, "Language set");
}
这篇关于我怎样才能改变我的应用程序的语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文