If there's one thing that developers like more than a bug-free code, it’s a properly implemented dark theme! Be it on their IDEs or in the apps they use, dark theme is an integral part of the entire developer culture.

And while it not only looks good, it has several other benefits like:

Reducing power usage by a significant amount

Improving visibility for users with low or limited vision and those who are sensitive to bright light.

Making it easier for anyone to use a device in a low-light environment.

With the introduction of Android 10, Google brought the much-awaited Dark Mode to the native Android framework and system apps.

In this blog post, we’ll be discussing how to add dark mode support to your Android app and have it adapt its theme to dark/light based on the user’s choice.

Adding the dark theme to your app

For the purpose of this blog post, we’ll be discussing how to add dark theme support to Android apps only. For iOS apps, you can take a look at this blog post.

Step 1: Ensure that your app is using either AppCompat or Material theme

To check this, you can open the res/values/styles.xml file and see what parent your theme extends from. It should be either AppCompat or MaterialComponents .

For example, this is what my styles.xml looks like

Step 2: Replace the parent theme with the DayNight variant of the same

The next step is to replace the parent theme’s color attribute (here AppCompat.Light ) with the DayNight variant of the same ( AppCompat.DayNight ).

Upon making the changes, this is what your styles.xml should look like: