Search code examples
androidandroid-activityandroid-theme

Theme.applyStyle() does not work after AppCompatDelegate.setDefaultNightMode()


If I set AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) when the system is dark in Android 12+ with dynamic colors enabled (cannot reproduce with dynamic colors disabled), Theme.applyStyle(, force = true) has no effect until I manually recreate the activity.

Sample code:

override fun onCreate(savedInstanceState: Bundle?) {
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
    super.onCreate(savedInstanceState)
    ColorPatchUtils.setTheme(R.styles.MyPartialTheme, true)
}

Solution

  • Known bug, which does not appear to have been fixed: https://issuetracker.google.com/issues/123835106