我正在使用下面的代碼來改變我的內部其他語言。但它總是採取應用程序內的語言更改後默認的字符串文件。另外在工作室中,新的其他語言字符串文件在相同的值文件夾中創建請幫助我。這裏是傳遞語言環境「ms-rMY」爲馬來語。我也嘗試過「ms」。檢查下面的代碼無法更改其他語言的字符串文件。它總是需要默認的字符串文件
public void updateLocale(String language) {
Locale myLocale = new Locale(language);
Locale.setDefault(myLocale);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
finish();
Intent refresh = new Intent(getApplicationContext(), MainActivity.class);
refresh.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(refresh);
}
你的代碼似乎沒問題,也許問題出在你的values-xx文件夾中,你可以嘗試一些更容易的事情,比如values-fr然後設置locale爲「fr」? – lelloman