

If you need to exclude some layout or widget from dark mode just add the property in the layout, android:forceDarkAllowed="false" Note: For Force Dark you app should target android-Q If you don't want to upgrade the Theme in Android Q, and keep it as it is you need to add the following in the App's theme: android:forceDarkAllowed="true"Īnd this will convert the whole app in Dark Mode. In the above code, we can select the theme based on the modes. LightMode -> tDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)ĭarkMode -> tDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)īatterySaverMode -> tDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)ĭefault -> tDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)

Private const val batterySaverMode = "battery" Now, to update the theme dynamically we have to use, tDefaultNightMode(/**Your Mode**/)

Set by Battery Saver (the recommended default option for Android P or before).We can also let user to change the theme while using the app. Note : If you want to replace the color in the app, you need to create a custom values directory, called values-night and for image resources as well we will create drawables-night. The above is the screenshot when you convert your style to Dark Mode.
