可能重複:
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' –