可能重复:
Change language programatically in Android我怎样才能改变我的应用程序的语言
我是新来的Android。在我的应用程序中,用户可以选择三种语言的语言。根据用户选择的语言,应该更改整个应用程序的语言。我怎样才能做到这一点?
可能重复:
Change language programatically in Android我怎样才能改变我的应用程序的语言
我是新来的Android。在我的应用程序中,用户可以选择三种语言的语言。根据用户选择的语言,应该更改整个应用程序的语言。我怎样才能做到这一点?
您可以设置区域设置。
Resources res = context.getResources();
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale(language_code.toLowerCase());
res.updateConfiguration(conf, dm);
使用此以编程方式更改语言:
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-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>
使用此改变语言编程: 'code' Locale locale = new Locale(“en_US”); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; context.getApplicationContext()。getResources()。updateConfiguration(config,null); setContentView(R.layout.activity_main); 'code' –