When I click on the "sub_changelang" button, it should change the program language to French for example. I got the following code to change the locale but I have no idea how to refresh/ pdate the app to change the language to French.
Button cl = (Button) findViewById(R.id.sub_changelang);
cl.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Locale locale = new Locale("fr_FR");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
}
});
It doesn't work. How can I fix it? I tried to add:
MainActivity.this.getResources().updateConfiguration(config, MainActivity.this.getResources().getDisplayMetrics());
but it didn't work. I also tried:
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
and it didn't work either.
android:configChanges="locale"
is set inside the AndroidMainfest.xml under application -> activity
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…