pull/32/head
Administrator 5 years ago
parent 39bd21ecff
commit cf4fb013dd
  1. 9
      app/src/main/java/io/legado/app/App.kt
  2. 9
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt

@ -51,12 +51,13 @@ class App : Application() {
.autoClear(false) .autoClear(false)
} }
fun initNightTheme() {//对整个应用生效,不要手动调用recreate fun initNightTheme() {
if (getPrefBoolean("isNightTheme")) { val targetMode = if (getPrefBoolean("isNightTheme")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) AppCompatDelegate.MODE_NIGHT_YES
} else { } else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) AppCompatDelegate.MODE_NIGHT_NO
} }
AppCompatDelegate.setDefaultNightMode(targetMode)
} }
/** /**

@ -40,8 +40,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
sharedPreferences ?: return sharedPreferences ?: return
when (key) { when (key) {
"transparentStatusBar" -> { "transparentStatusBar" -> {
postEvent(Bus.RECREATE, "") recreateActivities()
Handler().postDelayed({ activity?.recreate() }, 100)
} }
"colorPrimary", "colorAccent", "colorBackground" -> { "colorPrimary", "colorAccent", "colorBackground" -> {
if (backgroundIsDark(sharedPreferences)) { if (backgroundIsDark(sharedPreferences)) {
@ -104,6 +103,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
.putInt("colorBackgroundNight", App.INSTANCE.getCompatColor(R.color.md_grey_800)) .putInt("colorBackgroundNight", App.INSTANCE.getCompatColor(R.color.md_grey_800))
.apply() .apply()
App.INSTANCE.upThemeStore() App.INSTANCE.upThemeStore()
recreateActivities()
} }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show().upTint() .show().upTint()
@ -134,7 +134,12 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
private fun upTheme(isNightTheme: Boolean) { private fun upTheme(isNightTheme: Boolean) {
if (App.INSTANCE.getPrefBoolean("isNightTheme") == isNightTheme) { if (App.INSTANCE.getPrefBoolean("isNightTheme") == isNightTheme) {
App.INSTANCE.upThemeStore() App.INSTANCE.upThemeStore()
recreateActivities()
} }
} }
private fun recreateActivities() {
postEvent(Bus.RECREATE, "")
Handler().postDelayed({ activity?.recreate() }, 100L)
}
} }
Loading…
Cancel
Save