Is it possible to set the night mode only for a single Activity

Viewed 904

I am setting the night mode in onCreate of an activity. So every single activity in the app turns to night mode and all the previous activities gets recreated. But I need only that particular activity to be in night mode and all other activities to be in light mode. How to achieve this ? Below line of code I am using in oncreate of an activity to set to night mode.

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)

3 Answers

Try This to Set Modes Only for Single Activity


Light Mode

getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);

Dark Mode

getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);

System Default

getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);

sadly you don't have option for switching only one Activity into dark mode leaving all others in light. setDefaultNightMode is one and only method and it is working for whole Application and all Activities running in it.

you have to make two separated styles/themes for this one Activity and switch its theme programmatically (here you find out how) or if this one Activity is always dark then set its theme straight inside manifest

you can change the theme of the activity in the manifest file

Related