@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
PreferenceKeys preferenceKeys = new PreferenceKeys(getResources());
if(key.equals(preferenceKeys.night_mode_pref_key)){
SharedPreferences themePreferences = getActivity().getSharedPreferences(MainActivity.THEME_PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor themeEditor = themePreferences.edit();
//We tell our MainLayout to recreate itself because mode has changed
themeEditor.putBoolean(MainActivity.RECREATE_ACTIVITY, true);
CheckBoxPreference checkBoxPreference = (CheckBoxPreference)findPreference(preferenceKeys.night_mode_pref_key);
if(checkBoxPreference.isChecked()){
//Comment out this line if not using Google Analytics
themeEditor.putString(MainActivity.THEME_SAVED, MainActivity.DARKTHEME);
}
else{
themeEditor.putString(MainActivity.THEME_SAVED, MainActivity.LIGHTTHEME);
}
themeEditor.apply();
getActivity().recreate();
}
}
SettingsFragment.java 文件源码
java
阅读 37
收藏 0
点赞 0
评论 0
项目:Minimal-Todo
作者:
评论列表
文章目录