Light / Dark Themes

Support different custom attributes for Light and Dark themes

By default Theme.Kevin.Base theme is based on Material's DayNight theme which changes between light and dark based on the current device theme.

When you override an attribute, its value will be applied for both light and dark modes.

For example:

values/themes.xml
<resources>

    <!-- Red background color will be applied for both light and dark modes -->
    <style name="MyCustomTheme" parent="Theme.Kevin.Base">
        <item name="android:colorBackground">#FF0000</item>
    </style>

</resources>

To apply a different attribute values for light or dark mode, it is recommended to follow Android's best practice and create an alternative Android Resources Directory specifically for your light mode theme.

You can implement this similar to values-notnight or values-night example, depending on your project's structure:

values-notnight/themes.xml
<resources>

    <!-- Green background color will be applied for light mode -->
    <style name="MyCustomTheme" parent="Theme.Kevin.Base">
        <item name="android:colorBackground">#4CFF00</item>
    </style>

</resources>

Forcing Light or Dark theme

If you are only interested in using either light or dark mode exclusively you can do it by simply switching parent theme from Theme.Kevin.Base to:

Theme.Kevin.Base.Light - light mode

Theme.Kevin.Base.Dark - dark mode

This means that regardless of the active system theme, the SDK will adhere to either light or dark palette only.

You still have the option to customize each of the attributes, as demonstrated in the example below:

values/themes.xml
<resources>

    <!-- Green background color will be applied -->
    <!-- The rest of attributes will be taken from parent light theme -->
    <!-- Theme will not follow system's active theme -->
    <style name="MyCustomTheme" parent="Theme.Kevin.Base.Light">
        <item name="android:colorBackground">#4CFF00</item>
    </style>

</resources>

Last updated