Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Vasya Drobushkov: Android Dark Theme
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Vasya
July 19, 2019
Programming
0
200
Vasya Drobushkov: Android Dark Theme
How to support dark theme in your Android app
Vasya
July 19, 2019
Tweet
Share
More Decks by Vasya
See All by Vasya
Android Design Support Library
krossovochkin
0
290
Other Decks in Programming
See All in Programming
CDIの誤解しがちな仕様とその対処TIPS
futokiyo
0
220
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
290
How to stabilize UI tests using XCTest
akkeylab
0
130
Docコメントで始める簡単ガードレール
keisukeikeda
1
120
メタプログラミングで実現する「コードを仕様にする」仕組み/nikkei-tech-talk43
nikkei_engineer_recruiting
0
190
クライアントワークでSREをするということ。あるいは事業会社におけるSREと同じこと・違うこと
nnaka2992
1
350
AI時代のソフトウェア開発でも「人が仕様を書く」から始めよう-医療IT現場での実践とこれから
koukimiura
0
150
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
200
grapheme_strrev関数が採択されました(あと雑感)
youkidearitai
PRO
1
230
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
480
Claude Codeセッション現状確認 2026福岡 / fukuoka-aicoding-00-beacon
monochromegane
4
440
Claude Code Skill入門
mayahoney
0
400
Featured
See All Featured
Chasing Engaging Ingredients in Design
codingconduct
0
140
Git: the NoSQL Database
bkeepers
PRO
432
66k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
150
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.9k
WENDY [Excerpt]
tessaabrams
9
36k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
450
Amusing Abliteration
ianozsvald
0
140
Skip the Path - Find Your Career Trail
mkilby
1
84
We Have a Design System, Now What?
morganepeng
55
8k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2.5k
Writing Fast Ruby
sferik
630
63k
Darren the Foodie - Storyboard
khoart
PRO
3
2.9k
Transcript
Dark Theme
Vasya Drobushkov Android Developer @ Ciklum Github: @krossovochkin Medium: @krossovochkin
Android Oreo Wallpapers
Android Pie Display Settings
Android Pie Display Settings
Android Pie Display Settings
Android Pie Display Settings
Android Pie Night mode
Android Pie Night mode
Android Pie Night mode
Android Pie Night mode
Android Q Display Settings
Android Q Display Settings
Android Q Display Settings
Why? Environment Battery Accessibility
None
Force Dark <style name="AppTheme"> <item name="android:forceDarkAllowed">true</item> </style>
Force Dark Result Q+
DayNight Theme <style name="AppTheme" parent="Theme.AppCompat.DayNight" /> // OR <style name="AppTheme"
parent="Theme.MaterialComponents.DayNight" />
DayNight First Try
-night resources // values/themes.xml <style name="Theme.AppCompat.DayNight" parent="Theme.AppCompat.Light"/> // values-night/themes.xml <style
name="Theme.AppCompat.DayNight" parent="Theme.AppCompat"/>
Custom Night Resources // values-night/colors.xml <resources> <color name="colorPrimary">#511b43</color> <color name="colorPrimaryDark">#511b43</color>
<color name="colorAccent">#ff6868</color> </resources>
Default Updated
Force Dark Custom DayNight Background darker
Force Dark Custom DayNight Dividers are dark
Force Dark Custom DayNight Button style
Android P
Dynamic DayNight mode AppCompatDelegate.setDefaultNightMode(mode) getDelegate().setLocalNightMode(mode) System Application Activity
Night Modes • MODE_NIGHT_NO // LIGHT • MODE_NIGHT_YES // DARK
• MODE_NIGHT_AUTO_BATTERY // DARK IN BATTERY SAVE MODE • MODE_NIGHT_FOLLOW_SYSTEM // SYSTEM PREFERENCE
Application Settings setPreferencesFromResource(R.xml.preferences, rootKey) themePreference?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, mode
-> AppCompatDelegate.setDefaultNightMode(mode) true }
Application Settings (Q)
Application Settings (prior to Q)
Issue
Persistence class App : Application() { override fun onCreate() {
super.onCreate() val mode = PreferenceManager .getDefaultSharedPreferences(this) .getInt("theme_key", MODE_NIGHT_NO) AppCompatDelegate.setDefaultNightMode(mode)
Fixed
Sum up • Extend DayNight Theme • Provide additional -night
resources for Dark Theme • Add preference for changing mode inside Application • Persist preference choice • Work with designer for the rest
Test Dark Theme
Test force dark
Disable force dark for particular views <Button android:forceDarkAllowed="false" tools:targetApi="q"/> view.setForceDarkAllowed(false)
Attributes <TextView android:textColor="?android:attr/textColorPrimary" … />
Check is Dark theme applied fun Context.isDarkTheme(): Boolean { val
mode = this.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK return mode == Configuration.UI_MODE_NIGHT_YES }
AppCompat Material Components
AppCompat Material Components
Elevation val bg = MaterialShapeDrawable .createWithElevationOverlay(this, 32.0f) // OR val
color = ElevationOverlayProvider(this) .getSurfaceColorWithOverlayIfNeeded(32.0f)
https://github.com/krossovochkin/DarkThemeSample Sample project
Questions?