Slide 1

Slide 1 text

Bob Dahlberg Dark Mode

Slide 2

Slide 2 text

Dark Mode

Slide 3

Slide 3 text

The reasons Looks nice Less disturbing Battery saver Digital Eye Strain Melatonin

Slide 4

Slide 4 text

Structure

Slide 5

Slide 5 text

<style 
 name="BaseTheme" parent=“Theme.Appcompat.DayNight"> Base Theme Structure

Slide 6

Slide 6 text

Dark mode is a uiMode configuration change. Structure Base Theme Configuration Change

Slide 7

Slide 7 text

Only use styled attributes, no hard coded color- references and definitely no hard coded colors. Structure Base Theme Configuration Change Styled attributes

Slide 8

Slide 8 text

Only use styled attributes, no hard coded color- references and definitely no hard coded colors. 
 " Structure Base Theme Configuration Change Styled attributes

Slide 9

Slide 9 text

Only use styled attributes, no hard coded color- references and definitely no hard coded colors. 
 " Structure Base Theme Configuration Change Styled attributes

Slide 10

Slide 10 text

Base theme for margins, styles, sizes etc. <item name=“snackBarStyle”>@style/snack"</item> ! One theme for each flavor/dynamic theme <item name=“themeHeader”>@color/mode_header"</item> ! Structure Base Theme Configuration Change Styled attributes Theme

Slide 11

Slide 11 text

Base theme for margins, styles, sizes etc. <item name=“snackBarStyle”>@style/snack"</item> ! One theme for each flavor/dynamic theme <item name=“themeHeader”>@color/mode_header"</item> ! <item name=“themeHeader”>@color/mode_gt_header"</item> ! Structure Base Theme Configuration Change Styled attributes Theme

Slide 12

Slide 12 text

values/palette.xml #212121" #606060" #AFAFAF" #E6E6E6" #FAFAFA" " Structure Base Theme Configuration Change Styled attributes Theme 
 Colors

Slide 13

Slide 13 text

Structure Base Theme Configuration Change Styled attributes Theme 
 Colors values/scheme.xml @color/c5" @color/c1" " values-night/scheme.xml @color/c1" @color/c5" " values/palette.xml #212121" #606060" #AFAFAF" #E6E6E6" #FAFAFA" "

Slide 14

Slide 14 text

view.xml view.xml view.xml view.xml AppTheme attrs.xml view.xml palette.xml BaseTheme scheme.xml night/scheme.xml

Slide 15

Slide 15 text

view.xml view.xml view.xml view.xml AppTheme attrs.xml view.xml scheme.xml night/scheme.xml

Slide 16

Slide 16 text

view.xml view.xml view.xml view.xml AppTheme attrs.xml view.xml palette.xml BaseTheme KvpTheme GtTheme SportTheme DpTheme scheme.xml night/scheme.xml scheme_kvp.xml night/scheme_kvp.xml scheme_gt.xml night/scheme_gt.xml scheme_sport.xml night/scheme_sport.xml scheme_dp.xml night/scheme_dp.xml kvp/scheme.xml kvp-night/scheme.xml

Slide 17

Slide 17 text

Quirks

Slide 18

Slide 18 text

Themes are on Activity level Themes needs to be set before super.onCreate() The theme reference is held by context Creating Fragments uses that context Quirks Themes

Slide 19

Slide 19 text

If using the night qualifier only, make sure you target rather specific. It might be used by smart-phones with their own android OS… Either battery saving or custom theming or flags. Use values-night-v29 to be sure. Quirks Themes Night-Qualifier

Slide 20

Slide 20 text

Let the user choose 
 AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES) For the session, not persistent It recreates all Activites started. Even those on the back stack when brought back Quirks Themes Night-Qualifier AppCompatDelegate

Slide 21

Slide 21 text

Remember this? Quirks Themes Night-Qualifier AppCompatDelegate uiMode

Slide 22

Slide 22 text

Remember this? Don’t do it! Quirks Themes Night-Qualifier AppCompatDelegate uiMode

Slide 23

Slide 23 text

If you’re using the splash screen when booting the application it will follow the system. Quirks Themes Night-Qualifier AppCompatDelegate uiMode Splash screen

Slide 24

Slide 24 text

Last tip Throw the colors way off!

Slide 25

Slide 25 text

Last tip Throw the colors way off!

Slide 26

Slide 26 text

Kotlin Conf: - ASYNCHRONOUS DATA STREAMS 
 WITH KOTLIN FLOW
 - MIGRATING FROM RXJAVA TO FLOW
 - INTRO TO CHANNELS AND FLOW Questions? Thank you! Bob Dahlberg medium.com/dahlbergbob @mr_bob