MURAT YENER: Dark theme was one of the most requested
features in Android 10.
Dark theme is an alternative to Android's default light theme.
Dark theme is a system-wide setting
which applies to the system UI and all apps that support it.
On devices with OLED screens, dark theme
can reduce power usage by a significant amount.
Dark theme also improves usability
for users who have low vision, are sensitive to bright light,
or those who use their device in a low-light environment.
Apps don't automatically opt in to dark theme.
You must take some steps to allow your app
to appear in dark theme.
If you do, your app's behavior will
be consistent with the rest of the system and other apps
when dark theme is enabled.
There are two ways to implement dark theme.
The most simple way is to use Force Dark.
Force Dark is new Android [? time ?] feature
which automatically converts a light-theme UI
to a dark-themed UI.
Force Dark analyzes each screen of your app
and tries to automatically apply a dark theme on each view.
To enable Force Dark for your app,
set Android Force Dark Allowed to true in the app's theme.
When users turn on the system-wide dark theme
from settings, your app will be displayed in dark theme.
You should test your app in dark theme
and exclude views from Force Dark if necessary.
To exclude a view from dark theme,
set Force Dark Allowed to false on your view.
If your app uses webviews, Force Dark
works seamlessly with webviews and applies dark colors
to the web content, too.
You can also natively support dark theme in webviews
by using the new CSS media query prefers-color-scheme.
Force Dark is an easy and quick way to jump on dark theme,
but with Force Dark you cannot customize how colors are
darkened.
If you want to have full control over how your app is displayed
in dark mode, the recommended way to (DEEP ROBOTIC VOICE)
join the dark theme is to create a custom theme.
To create a custom dark theme, change your app's theme
to extend from one of the AppCompat or material
components day/night variance.
You also need to enable dark theme in your app
by using setDefaultNightMode on AppCompatDelegate.
You can use any of the following options with this API.
Note this setting is not persistent.
You must call the static method every time
your app process is started.
To make sure this call is done every time,
you can use the application class.
This enables the night qualifier for your app
when it runs in dark theme.
Once you switch to a day/night variant,
you can provide alternative resources
for your light and dark UIs by using the night qualifier
on your resource folders.
Keep in mind that your users may want
to use your app in a different theme than the system,
such as Always Dark or Always Light.
We highly recommend giving your users
the option to choose any theme they
want in your app's settings.
Once you go dark, if you run into behaviors like this,
your app most likely has static colors in its views.
Instead of using static colors, prefer using theme attributes.
The theme can provide the right color for your app, and if not,
you can always overwrite it.
That's it.
If you want to learn more about dark theme,
check out the Developing Themes with Style talk, which
is linked in the notes below.
Also, if you liked the video, please hit the Like button,
and subscribe to the channel for more awesome Android videos.
Thanks for watching.
Use the source.
And (DEEP ROBOTIC VOICE) join the dark theme.
[MUSIC PLAYING]