android - 如何更改应用程序的语言

标签 android internationalization

Possible Duplicate:
Change language programatically in Android

我是 Android 新手。在我的应用程序中,用户可以从三种语言中选择一种语言。根据用户选择的语言,应该改变整个应用程序的语言。我该怎么做?

最佳答案

使用它以编程方式更改语言:

Locale locale = new Locale("en_US"); 
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);

写下该语言的国家代码来代替您想要的任何语言的 "en_US"。例如,对于日语,ja_JP;对于阿拉伯语,ar。查看 this link列表。

res/values-ja 中创建一个文件夹用于日语或 res/values-ar 用于阿拉伯语..

并制作一个 string.xml 文件,并在布局上放置您想要的任何语言。它将从 values 文件夹中获取默认语言,否则如果您需要手动获取,它将从您的外部文件夹 values-ar 等中获取。

res/values-ar 的例子,用于阿拉伯语:

<?xml version="1.0" encoding="UTF-8"?>
  <resources>
    <string name="label">حسب</string>
    <string name="name">بحث</string> 
    <string name="search">بحث :</string>
 </resource>

关于android - 如何更改应用程序的语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6464771/

相关文章:

android - 是否必须在应用程序包中包含所有可绘制文件夹的图标?

reactjs - React-intl 多语言应用程序 : changing languages and translations storage

xslt - XSL 与区域化/国际化数字格式

iOS 检测键盘布局(例如 QWERTY、AZERTY)

android - 将依赖项添加到模块 - 外部库错误

java - RecyclerView 未获取列表(响应)

java - 安卓 : Change background color of table rows when it is clicked

python - 使用 babel、django 和 jinja2 提供 i18n js 服务

c++ - 完整的 C++ i18n gettext() "hello world"示例

Android ninepatch工具源码