Fix language switch for Application context (#1662)

Fix #1658
This commit is contained in:
LoveSy 2022-02-10 14:06:30 +08:00 committed by GitHub
parent 3bcb2867b7
commit a983f33551
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -280,6 +280,11 @@ public class SettingsFragment extends BaseFragment {
language.setOnPreferenceChangeListener((preference, newValue) -> {
var locale = SYSTEM.equals(newValue) ? LocaleDelegate.getSystemLocale() : Locale.forLanguageTag((String) newValue);
LocaleDelegate.setDefaultLocale(locale);
var res = App.getInstance().getResources();
var config = res.getConfiguration();
config.setLocale(locale);
var metric = res.getDisplayMetrics();
App.getInstance().getResources().updateConfiguration(config, metric);
MainActivity activity = (MainActivity) getActivity();
if (activity != null) {
activity.restart();