Fragments are widely used in my application. It is supposed to support 3 languages ββ- English, Arabic and Kurdish. The main screen consists of a navigation box, in which there is a menu of options, one of which is the languages ββthat open the language selection dialog. The language selector has 3 buttons - English, Kurdish and Arabic, pressing the button changes the language like this:
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 added the following code in 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 added in android manifest - the following:
android:configChanges="locale"
but nothing similar happens. I also tried - Is it possible to update a fragment view without much luck. Any help is appreciated. Thanks in advance.
source share