VOOZH about

URL: https://www.geeksforgeeks.org/android/how-to-implement-dark-night-mode-in-android-app/

⇱ How to implement Dark (Night) mode in Android app - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to implement Dark (Night) mode in Android app

Last Updated : 12 Jul, 2025

Light-on-dark color scheme, also called dark mode, is a supplemental mode that uses a color scheme in which content of a webpage is displayed on a dark background. Such a color scheme reduces the light emitted by screens and enhances readability. Switching to dark mode allows website users to move to an eye-friendly and resource-saving design whenever they want.

Dark mode or night mode has been getting a lot of buzz lately as Google has included it in their Latest Android version i.e. Android Q (API Level 29) and following that more and more apps started supporting dark mode natively because it has many benefits:

  • Reduces battery/power usage.
  • Improves visibility for users with low vision and those who are sensitive to bright light.
  • Makes it easier to use the device in a low-light.
  • Step by Step Implementation

    Step 1: Create a New Project

    To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

    Step 2: Create night theme colors.xml

    Navigate to app > res > values, right click on the folder and select New > Value Resource File.

    👁 value-resource-file-navigate


    Now, a new dialog box will open. Set the file name as colors.xml, in the section "Available qualifiers:", choose Night mode and click the ">>" button. Now, in the new "Night mode:" drop down menu select Night. Then, click OK.

    👁 colors-night-dialog-box


    Step 3: Working with colors.xml

    Now, there are two colors.xml files, one for light mode and other night mode. Let's customise for both light/dark mode. Add the following color attributes in both the files to setup dark mode.


    Step 4: Working with activity_main.xml

    Navigate to app > res > activity_main.xml and add a button or switch to toggle On/Off Dark Mode and some texts and images. Now, add the colors to the views to make it toggle on switch click.

    activity_main.xml:


    Step 5: Working with MainActivity

    In this file, simply use the AppCompatDelegate.setDefaultMode() and the switch to toggle between light and dark mode.

    MainActivity File:


    Step 6: Further - Save theme state locally

    Save the state of the app so that, when the user reopens the app after applying Dark/Light Mode that mode retains. We will use SharedPreferences to save the state of the app.

    Refer to the following github repo to get the entire code:Dark-Mode-Android

    Output:


    Comment
    Article Tags:

    Explore