Hello,
I am developing an android app in android studio and I want to translate the app in two languajes. I have develop the following code in order to translate all my activities. It is codify only in the login activity (the main one). With this code it not translates all the activities at once. Do I have to create code in the rest of activities too?
Thanks and regards.
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.espanol:
Locale locale_es = new Locale("es");
Locale.setDefault(locale_es);
Configuration config_es = new Configuration();
config_es.locale = locale_es;
getBaseContext().getResources().updateConfiguration(config_es, getBaseContext().getResources().getDisplayMetrics());
recreate();
break;
case R.id.english:
Locale locale_en = new Locale("en");
Locale.setDefault(locale_en);
Configuration config_en = new Configuration();
config_en.locale = locale_en;
getBaseContext().getResources().updateConfiguration(config_en, getBaseContext().getResources().getDisplayMetrics());
recreate();
break;
}
return super.onOptionsItemSelected(item);
}
I am developing an android app in android studio and I want to translate the app in two languajes. I have develop the following code in order to translate all my activities. It is codify only in the login activity (the main one). With this code it not translates all the activities at once. Do I have to create code in the rest of activities too?
Thanks and regards.
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.espanol:
Locale locale_es = new Locale("es");
Locale.setDefault(locale_es);
Configuration config_es = new Configuration();
config_es.locale = locale_es;
getBaseContext().getResources().updateConfiguration(config_es, getBaseContext().getResources().getDisplayMetrics());
recreate();
break;
case R.id.english:
Locale locale_en = new Locale("en");
Locale.setDefault(locale_en);
Configuration config_en = new Configuration();
config_en.locale = locale_en;
getBaseContext().getResources().updateConfiguration(config_en, getBaseContext().getResources().getDisplayMetrics());
recreate();
break;
}
return super.onOptionsItemSelected(item);
}