Implementing Night/Dark Mode to Existing/New Android app

Deepak Prasad
Apr 26, 2019 · 2 min read

We will not go into details of why we should be implementing night/dark mode. We shall straight dive into details of how to implement this.

Image for post
Image for post
Day-Night mode with Icons/Text changing colors with theme.

Step 1

Add a custom theme to styles.xml file.

Here the Base application theme is defined by default or is the old application theme that your app used earlier.

The Custom application theme is using Android’s default DayNight mode as parent and will help us in configuring the Dark/Night Mode.

Step 2

Change theme parameter of each Activity in the Manifest file to AppTheme.DayNight.

Add theme to each activity that needs to implement the night mode theme.

Step 3

We have now successfully added Night mode to our app. For the theme to take effect, we need to add the following lines to every Activity’s onResume function:


Changing Icons’ color with changing theme

There may be some icons which also need to change colors with the change in theme.

Image for post
Image for post
Icons inverting colors as per theme

For this we will be using Vector Drawables.

Create a new vector drawable for the existing icon and add attribute android:fillColor as shown below.


Further we can also add a Toggle to change theme in the Settings of the App using SharedPreferences. An example is shown here.

Image for post
Image for post
Adding toggle for Night Mode.

Link to CryptoTrack : Playstore

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store