Reputation: 3885
My preferences are setup via PreferenceActivity
which in onBuildHeaders()
loads the PreferenceFragments
from <preference-headers>
xml resource.
One of those fragments holds a ListPreference
with languages.
OnSharedPreferenceChangeListener
is correctly (un)registered and onSharedPreferenceChanged()
is correctly called. When the onSharedPreferenceChanged()
is called, first I update the default locale:
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
mContext.getResources().updateConfiguration(config, mContext.getResources().getDisplayMetrics());
then I update titles and summaries of preferences of this fragment (which correctly pull strings from newly set locale).
Going back triggers onResume
in PreferenceActivity
:
@Override
protected void onResume() {
super.onResume();
invalidateHeaders();
}
which forces preference fragments to correctly display their titles in newly set locale.
All that is fine, but what troubles me is that:
PreferenceFragment
title is not changedPreferenceActivity
title is not changedHow can I fix that?
(minSdkVersion is 15)
Upvotes: 0
Views: 508
Reputation: 3885
Solved it myself. Here are all the aspects...
PreferenceFragment
title is not changedWhen updating title and summaries in PreferenceFragment
also update PreferenceActivity
title (which actually provides title for the PreferenceFragment
):
getActivity().setTitle(getString(R.string.title_activity_settings));
PreferenceActivity
title is not changedIn onResume()
of the PreferenceActivity
, update its title:
setTitle(getString(R.string.title_activity_settings));
Track locale (String) in onCreate()
of MainActivity and compare it to current locale (String) in onResume()
. If different, restart the activity with:
Intent intent = getIntent();
finish();
startActivity(intent);
Upvotes: 1