设置语言环境编程 [英] Set Locale programatically

查看:138
本文介绍了设置语言环境编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序支持3(很快4)语言。由于一些语言环境是非常相似的,我想给用户选择改变区域设置在我的应用程序,比如一个意大利人可能preFER西班牙语过英语。

My app supports 3 (soon 4) languages. Since several locales are quite similar I'd like to give the user the option to change locale in my application, for instance an Italian person might prefer Spanish over English.

有没有办法为用户可用应用程序的语言环境中进行选择,然后改一下语言环境中使用?我不认为这是一个问题,设置区域设置每一项活动,因为它是一个简单的任务,在基类来执行。

Is there a way for the user to select among the locales that are available for the application and then change what locale is used? I don't see it as a problem to set locale for each Activity since it is a simple task to perform in a base class.

推荐答案

希望这有助于(在onResume):

Hope this help(in onResume):

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

这篇关于设置语言环境编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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