嗨每個人我試圖在我的應用程序上創建一個功能,將改變語言(Android上)的事情是,它不是真的很好,因此我必須重新啓動我的應用程序爲了適用語言更改彈出窗口,將重新啓動應用程序Android
我想要實現的是首先選擇語言彈出,然後通知用戶應用程序將重新啓動,以便應用更改。
這裏是一段代碼,我使用更改語言和應用以保存更改語言,當它重新啓動:
公共類LocalizationUpdaterActivity延伸活動{
private String[] languages = { "English", "Francais", "Espanol", "Ivrit" };
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_langues);
SharedPreferences sp = this.getApplicationContext().getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = sp.edit();
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
spinner.setPrompt("select language");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, languages);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView arg0, View arg1,
int arg2, long arg3) {
Configuration config = new Configuration();
switch (arg2) {
case 0:
config.locale = Locale.ENGLISH;
editor.putString("Langues", "en_US");
break;
case 1:
config.locale = Locale.FRENCH;
editor.putString("Langues", "fr_FR");
break;
case 2:
config.locale = new Locale("es_ES");
editor.putString("Langues", "es_ES");
break;
case 3:
config.locale = new Locale("he", "IL");
editor.putString("Langues", "he_IL");
break;
default:
config.locale = Locale.ENGLISH;
editor.putString("Langues", "en_US");
break;
}
getResources().updateConfiguration(config, null);
}
public void onNothingSelected(AdapterView arg0) {
// TODO Auto-generated method stub
}
});
}
}