多国语言Android应用程序? [英] multi language android application?

查看:132
本文介绍了多国语言Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须让我的Andr​​oid应用程序在3种语言,即德语,英语和荷兰语。我在我的Andr​​oid应用程序的名称值德发三个文件夹值-NL res目录中。 现在,当用户选择一个特定的语言,我执行以下code:

I have to make my Android application in 3 languages ie German, English and dutch. i have made three folders in my android application names values-de and values-nl within the res directory. now when the user selects a specific language i perform the following code:

Resources res = getResources();
Configuration newConfig = new Configuration(res.getConfiguration());
newConfig.locale = Locale.ENGLISH;
res.updateConfiguration(newConfig, null);

在不同的价值观的文件夹具有相同名称的所有字符串,即字符串中的值的文件夹名称add_site在同名值-DE 文件夹,但用不同的值。 我的应用程序没有加载时,我把场景设置成德国德国价值?可能是什么问题?

all the strings in the different values folders have the same name, i.e a string with name add_site in the values folder has the same name in the values-de folder but with a different value. My application is not loading the German value when i set the locale to German? what could be the problem?

感谢您对您有所帮助。

推荐答案

尝试把这个在的onCreate()只需调用超后。的onCreate

Try putting this in onCreate() just after the call to super.onCreate:

Locale locale = new Locale("de");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
      getBaseContext().getResources().getDisplayMetrics());

编辑: 这里是另一种方法。这似乎是非常灵活的,但似乎在评论一些分歧是否适用于所有的Andr​​oid版本。

Here's another approach. It seems to be very flexible, but there seems to be some disagreement in the comments whether it works on all Android versions.

这篇关于多国语言Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆