I want to programmatically change the language.
So I have built two xml files.
values-it
-->string.xml
values-en
-->string.xml
This is the code in MainActivity to change the language of the whole application:
//ITALIAN
Resources res = getApplicationContext().getResources();
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale("it");
res.updateConfiguration(conf, dm);
//ENGLISH
Resources res2 = getApplicationContext().getResources();
DisplayMetrics dm2 = res2.getDisplayMetrics();
android.content.res.Configuration conf2 = res2.getConfiguration();
conf2.locale = new Locale("en");
res2.updateConfiguration(conf2, dm2);
Now if I set the English language (for example) the code is executed with no error, but the label doesn't not change its text.
If I change the orientation of my device, the label changes its text correctly.
Now how can I modify my code to automatically refresh the label?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…