My app uses fragments extensively. It is supposed to support 3 languages - English, Arabic and Kurdish. The home screen consists of a navigation drawer which holds a menu of options one of them is languages which opens a language selector dialog. The language selector has 3 buttons - English, Kurdish and Arabic clicking on a button changes the language like so -
private void setLocale(String code){
Configuration config=new Configuration();
Locale locale = null;
locale=new Locale(code);
Locale.setDefault(locale);
config.locale=locale;
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
dismiss();
}
I have added the following code to onConfigurationChange -
FragmentManager fragmentManager = getSupportFragmentManager();
int count=fragmentManager.getBackStackEntryCount();
BackStackEntry latestEntry=(BackStackEntry) fragmentManager.getBackStackEntryAt(count-1);
String str=latestEntry.getName();
Fragment fragment=fragmentManager.findFragmentByTag(str);
if(fragment==null){
return;
}
FragmentTransaction fragTransaction = fragmentManager.beginTransaction();
fragTransaction.detach(fragment);
fragTransaction.attach(fragment);
fragTransaction.commit();
And I have added the following to android manifest -
android:configChanges="locale"
but nothing seems to be happening. I also tried - Is it possible to refresh the view of a Fragment without much luck. Any help is appreciated. Thanks in advance.