在我的应用程序中,我尝试通过单击按钮(英语/意大利语)来更改语言。我选择默认语言环境英语。当打开活动并按下意大利语按钮时,它发生了变化,但之后我无法选择英语。换句话说,语言只改变了一次。我做错了什么?
public class MainActivity extends DefaultActivity implements View.OnClickListener {
String LOCALE_ITALIAN = "it";
String LOCALE_ENGLISH = "en";
Locale mLocale;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLocale = new Locale(LOCALE_ENGLISH);
Locale.setDefault(mLocale);
Configuration config = new Configuration();
config.locale = mLocale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
setContentView(R.layout.main);
findButton(R.id.english).setOnClickListener(this);
findButton(R.id.italian).setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.english:
mLocale = new Locale(LOCALE_ENGLISH);
Locale.setDefault(mLocale);
Configuration config = new Configuration();
config.locale = mLocale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
MainActivity.this.setContentView(R.layout.main);
break;
case R.id.italian:
mLocale = new Locale(LOCALE_ITALIAN);
Locale.setDefault(mLocale);
Configuration config1 = new Configuration();
config1.locale = mLocale;
getBaseContext().getResources().updateConfiguration(config1,
getBaseContext().getResources().getDisplayMetrics());
MainActivity.this.setContentView(R.layout.main);
break;
}
}
}