Search code examples
androidkotlinandroid-themematerial-components-androidandroid-dark-theme

How do I make my app not switch themes while in game


I'm doing a simple Math game for Android and it turns on dark mode on/off depending on the system settings; I used Theme.MaterialComponents.DayNight.NoActionBar as my theme's parent. However, I don't want the game to suddenly change themes in-game for it'll be jarring to the user and the redrawing of the screen will cause a jitter (and possibly, bugs).

I want to make the app not change themes until the game ends and I will just call fun syncTheme() or something to sync the theme with the system settings in another activity.


Solution

  • You can add android:configChanges="uiMode" to the <activity> element for your game in your AndroidManifest.xml. This will prevent you from receiving configuration change events by declaring that you will handle UI mode changes (which includes night mode and car/desk modes) yourself manually.