Dark theme in Android

Updated 29 June 2020

Save

Dark theme in Android :

Dark theme in Android:  displays dark surfaces across the majority of a UI. It’s designed to be a supplemental mode to default (or light) theme.

Dark theme is available in Android 10 (API level 29) and higher. It has many benefits:

Supporting the Dark theme in your app :

You can also use MaterialComponents’ dark theming:

Here are the two most important theme attributes to know about:

We recommend using Material Design Components, since its color theming system (such as the theme attributes ?attr/colorSurface and ?attr/colorOnSurface) provides easy access to suitable colors. Of course, you can customize these attributes in your theme.

When running on devices running Android 9 or earlier, the recommended theme options are:

When running on Android 10 (API level 29) and higher, the recommended options are different, to allow the user to override the system default:

Note that if the user selects Light, then Battery Saver will not change that setting.

Each of the options map directly to one of the AppCompat.DayNight modes:

To switch the theme, call AppCompatDelegate.setDefaultNightMode().

Let’s do some real code:

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home