The System Override Solution
You could try to cheat a bit and have the system create a dark theme for you on the fly. For that, add this entry to your theme resource:
<item name="android:forceDarkAllowed">true</item>
Then, on Android 10 and higher devices, the system will examine your UI and swap colors to try to make the app appear dark. It even has the smarts to determine whether an ImageView
appears to be containing an icon (that might be converted) or a photo (that should not be converted).
So, in the default mode, you might have:
…while if the user opts into the dark mode, android:forceDarkAllowed="true"
will give the user:
This is quick and easy. However:
- You do not have any control over the color substitutions, which may make your designers unhappy
- Some things may get converted by accident, requiring you to add
android:forceDarkAllowed="false"
to individual widgets to get them to be left alone - This only works on Android 10 and higher, so you will have different behavior by OS version
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.