1
我用下面的代碼來改變語言:使用SharedPreferences更改啓動活動中的應用程序語言?
public void setLocale(String languageToLoad){
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getResources().updateConfiguration(config,getBaseContext().getResources().getDisplayMetrics());
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
我的問題是,當我嘗試加載「區域設置」使用SharedPreferences它似乎是陷阱在一個循環中,因爲清爽的活動。所以我怎樣才能加載最後的定位在開始活動。 在此先感謝。
調用setLocale的代碼在哪裏? –
您可以比較用設置的區域設置設置的區域設置嗎?如果他們是一樣的,什麼都不做? –