Android Switching between Dark/Light themes not working

608 views Asked by At

I am working on an Android project where I need to support switching between Dark/Light themes based on system setting preference.

I have changed App Theme from Theme.AppCompat.Light.NoActionBar to Theme.AppCompat.DayNight.NoActionBar.

I am using this API on Application onCreate() AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);

App theme is getting updated only when I restart app but does not update when I am within the app when theme is changed from system setting.

Am I missing any config changes?

1

There are 1 answers

1
user14678216 On

I believe that the issue lies with the android:configChanges tag. This is because the activity needs to be recreated when the theme is changed. You will have to remove the tag and use onSavedInstanceState to save the state of your current activity.