Having this setup
<style name="Theme.App" parent="Theme.Material3.DayNight">
<item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>
</style>
<style name="WindowAnimationTransition" parent="@android:style/Animation.Activity">
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
<item name="android:activityOpenEnterAnimation">@android:anim/fade_in</item>
<item name="android:activityOpenExitAnimation">@android:anim/fade_out</item>
<item name="android:activityCloseEnterAnimation">@android:anim/fade_in</item>
<item name="android:activityCloseExitAnimation">@android:anim/fade_out</item>
</style>
It works in Android 21 or 22 (Lollipop) and 23 (Marshmallow) when activity is recreated after calling AppCompatDelegate.setDefaultNightMode
. However, it is not working with SDK 24 (Nougat) and above. I cannot find any documentation stating the reason why, my only guess is there is some optimization going on so the activity is not recreated and only does some partial re-rendering. Is this expected behavior or is there something I need to add more? Reading the documentation for setDefaultNightMode
seems to support my idea of what is going on.
Ensure You Are Using AppCompat Theme: