0

I have added five fragments in my activity. also i have added Theme.Material3.Light.NoActionBar theme to both of my day and night theme in app. when i change theme from quick toggle theme changer, theme is changing but fragment is restarting. attached .gif video for better understanding what i want to tell.

I tried changing android:configChanges="uiMode" but it didn't work as it is not switching theme in app upon changing from system.

enter image description here

1
  • If the fragment didnt restart then the updated day/night theme wouldnt be applied
    – tyczj
    Commented May 13 at 12:56

1 Answer 1

0

Android restarts Activity when theme is changed (configuration change) to ensure everything is drawn according to a new theme. If you use uiMode you inform the system that you will handle the configuration change on your own, in onConfigurationChanged callback, hence no activity and a fragment restart.

Alternatively you can ensure the fragment state is persisted and restored as expected.

Not the answer you're looking for? Browse other questions tagged or ask your own question.