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)
}
fun initNightTheme() {//对整个应用生效,不要手动调用recreate
if (getPrefBoolean("isNightTheme")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
fun initNightTheme() {
val targetMode = if (getPrefBoolean("isNightTheme")) {
AppCompatDelegate.MODE_NIGHT_YES
} 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
when (key) {
"transparentStatusBar" -> {
postEvent(Bus.RECREATE, "")
Handler().postDelayed({ activity?.recreate() }, 100)
recreateActivities()
}
"colorPrimary", "colorAccent", "colorBackground" -> {
if (backgroundIsDark(sharedPreferences)) {
@ -104,6 +103,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
.putInt("colorBackgroundNight", App.INSTANCE.getCompatColor(R.color.md_grey_800))
.apply()
App.INSTANCE.upThemeStore()
recreateActivities()
}
.setNegativeButton(R.string.cancel, null)
.show().upTint()
@ -134,7 +134,12 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
private fun upTheme(isNightTheme: Boolean) {
if (App.INSTANCE.getPrefBoolean("isNightTheme") == isNightTheme) {
App.INSTANCE.upThemeStore()
recreateActivities()
}
}
private fun recreateActivities() {
postEvent(Bus.RECREATE, "")
Handler().postDelayed({ activity?.recreate() }, 100L)
}
}
Loading…
Cancel
Save