Implementing Night/Dark Mode to Existing/New Android app

Deepak Prasad
Apr 26 · 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.

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:

// for enabling night mode
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);

Changing Icons’ color with changing theme

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

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.

Adding toggle for Night Mode.

Link to CryptoTrack : Playstore