Implementing Dark Mode on Android — part one

Lessons learned from a single Activity, multi-flavored, dynamically themed Application

Photo by Kelly Sikkema on Unsplash

My Baseline

Colors; got to get them all!

Make your attributes

The theme

Let’s look at the content background color full chain to clarify

// file: values/palette_spec.xml 
// Here I specify all colors allowed
<color name="c1">#212121</color> // almost black
<color name="c5">#FAFAFA</color> // almost white
// file: values/palette.xml
// And the light mode specific palette
<color name="mode_color_background">@color/c5</color>
// file: values-night/palette.xml
// And the light mode specific palette
<color name="mode_color_background">@color/c1</color>
// file: values/attrs.xml
// The styled attribute to be used by the views
<attr name="themeContentBackground" format="color" />
// file: values/theme.xml
// And in our theme that connect our attributes with colors
<item name="themeContentBackground">
@color/mode_content_background
</item>

Make our views depend on the theme

Done?

Lead Developer at Qvik, Coach, Agile Thinker, GDG Lead.

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