我怎样才能改变我的应用程序的语言 [英] How can I change language of my application

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

问题描述

可能重复:
  变化的Andr​​oid 编程语言

Possible Duplicate:
Change language programatically in Android

我是新来的Andr​​oid。在我的应用程序,用户可以选择三种语言的语言。基于由用户选择的语言时,整个应用程序的语言不应被改变。我怎样才能做到这一点?

I am new to Android. In my application user can select a language from three languages. Based on the language selected by user, the entire application's language should be change. How can I do this?

推荐答案

使用这种以编程方式来改变语言:

Use this to change the language by programmatically:

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

编写语言的国家code代替EN_US的任何一种语言,你婉。例如,对于日本, Ja_JP表示;为阿拉伯语, AR 。检查此链接的列表。

Write the country code of the language in place of "en_US" for whatever language you wan. For example, for Japanese, ja_JP; for Arabic, ar. Check this link for a list.

,并在 RES /值-JA 日本或 RES /值-AR 阿拉伯语的文件夹。

And make a folder in res/values-ja for Japanese or res/values-ar for Arabic..

和作出 string.xml 文件,并把任何语言你想在你的布局。这将获取的默认语言的值,文件夹,否则想手动它,然后它会读取来自外部文件夹值-AR 等。

And make a string.xml file, and put whatever languages you want on your layout. It will fetch the default language from values folder otherwise you want it manually then it will fetch from your external folder values-ar, etc.

的例子 RES /值-AR 阿拉伯语:

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

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

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