Dark-mode support on your Android app

Nobody enjoys white light right in front of their eyeballs, trust me, your users might want something a bit more soothing when moving through your Android Application.

Luckily, how to add dark mode support on your app is exactly what this article is about!

Step 1: Change the theme to DayLight.

In styles.xml, change the AppTheme parent theme from Light to DayNight:

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">

Step 2: Turn on the dark theme.

In MainActivity’s onCreate(), call AppCompatDelegate.setDefaultNightMode() to turn on the dark theme:

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)

There you have it – run the app and verify that it has switched to dark theme!

Free Resources