Share
Embed
Transcript
46 slides
-
Android Dark Theme উࢿਊ (NAVER) Android Dark Theme extended Dark
Theme 안성용 Android Developer at NAVER SOUP GDG Korea Slack [email protected] -
extended • Why? • OS Setting • Force Dark •
DayNight • App theme setting • MDC 1.1.0 ݾର -
extended OS Setting • Android Q Settings > Display >
Dark Theme ( 'যف ప݃' QuickSettingب ࢜۽. ୶оؽ ) • Android P Settings > System > Developer options > Night mode ( ࢿ ױ݈ 'ঠр ݽ٘' QuickSetting ઁҕ ) New in Q -
extended extended Force Dark New in Q • Qࠗఠ ࢎਊ
оמ • জਸ ప݃۽ ز ߸ജೞח ӝמ • ӝࠄ Force Dark Disable -
extended • ݽٚ জਸ force-dark۽ ߄Լࠁח ѐߊ ݽ٘ • Android
Q Settings > System > Developer options > Override dark-mode Override Force Dark • ೞ݅ Q Beta4 ীࢲח زೞ ঋח. " F O R C E D A R K -
extended • জী ਊೞ۰ݶ ప݃ forceDarkAllowed ࣘࢿਸ true۽ ߸҃ೞݶ ػ.
• ױ, Light ప݃݅ ForceDarkо ਊؼ ࣻ . <style name="AppTheme" parent="@style/Theme.MaterialComponents.Light> <item name="android:forceDarkAllowed">true</item> </style> Enable Force Dark F O R C E D A R K <style name="Theme.AppCompat.Light" parent="..."> <item name="isLightTheme">true</item> </style> -
extended Disable Force Dark (Partially) F O R C E
D A R K • Force Darkܳ ࠗ࠙ਵ۽ ઁ৻ೡ ࣻ . // For Kotlin view.isForceDarkAllowed = false // For Java view.setForceDarkAllowed(false) <!-- For Layout XML --> <View android:forceDarkAllowed="false" /> • ViewGroupী ਊೞݶ ೞਤ View ݽفী ਊغ݅, true۽ ࢸೞݶ ࠗݽ/ध View falseܳ ޖदೠ. -
extended DayNight • ప݃ীࢲח -night resource qualifierо ഝࢿചػ. •
Android 4.0 (API14) ࢚ ਗ • AppCompat 1.1.0ীࢲ ز ѐࢶ -
extended • ܻࣗझח qualifierী ٮۄ ଵઑػ. • drawable-xxhdpi / values-ko
/ values-land ١ ܻࣗझ ಫ؊ܳ ݆ ࢎਊೞחؘ, ৈӝࢲ xxhdpi, ko, landо resource qualifierী ೧ػ. • Drawableਸ ۽ ٜয, drawable-hdpi ঠрݽ٘ ܻࣗझח drawable-night-hdpiী ֍Ҋ drawable-land ঠрݽ٘ ܻࣗझח drawable-land-nightী ֍ח Ѫ ೞ. Resource Qualifier D A Y N I G H T Qualifier: https://developer.android.com/guide/topics/resources/providing-resources#AlternativeResources -
extended Resource Qualifier (-night) D A Y N I G
H T • ܲ ܻࣗझۢ -night ಫ؊ী ܻࣗझܳ ୶оೞݶ ػ. <!-- values/colors.xml --> <color name=“colorCustom">#000000</color> <!-- values-night/colors.xml --> <color name=“colorCustom">#ffffff</color> res/drawable/ic_example.png res/drawable-night/ic_example.png -
extended D A Y N I G H T values/theme.xml
<style name="Theme.AppCompat.DayNight" parent="Theme.AppCompat.Light" /> values-night/theme.xml <style name="Theme.AppCompat.DayNight" parent="Theme.AppCompat" /> values/theme.xml <style name="Theme.MaterialComponents.DayNight" parent="Theme.MaterialComponents.Light" /> values-night/theme.xml <style name="Theme.MaterialComponents.DayNight" parent="Theme.MaterialComponents" /> Theme -
extended • MODE_NIGHT_YES ೦࢚ যنѱ द • MODE_NIGHT_NO ೦࢚ ߋѱ
द • MODE_NIGHT_FOLLOW_SYSTEM दझమ ࢸী ٮۄ ߸҃ • MODE_NIGHT_AUTO_BATTERY ݽ٘ীࢲ যنѱ द Modes D A Y N I G H T App Compat 1.1.0 API21 ↑ -
extended • ప݃ ݽ٘ ࢸೞח ߑߨ // AppCompatDelegate.java public
abstract void setLocalNightMode(@NightMode int mode); public static void setDefaultNightMode(@NightMode int mode) { ... } • ଵҊ: ч in-memoryী غ۽, ߹ب۽ чਸ /ࠂҳ ೧ঠ ೠ. Set / Get night mode D A Y N I G H T • ప݃ ৈࠗܳ ഛੋೞח ߑߨ fun isDarkTheme(config: Configuration): Boolean { return config.uiMode and // andח &৬ زੌ Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES } -
extended • UiModeо ߸҃ؼ ٸ, DayNight UIܳ ਊೡ ࣻب
. Manual DayNight D A Y N I G H T <!-- AndroidManifest.xml --> <activity android:name=“.MainActivity" android:configChanges="uiMode" /> class MainActivity : AppCompatActivity() { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) val isDarkTheme: Boolean = isDarkTheme(newConfig) ... UI সؘ ... } } -
extended • ইېח ҳӖীࢲ ӂೞח OS ߡ߹ জ ప݃ ࢸ
২࣌ੑפ. Android Q ࢚: • ߋѱ • যنѱ • दझమ ࢸ (ӝࠄ) Recommended A P P T H E M E S E T T I N G Android P ೞ: • ߋѱ • যنѱ • ݽ٘ ࢸ (ӝࠄ) -
extended DayNight Modes A P P T H E M
E S E T T I N G MODE_NIGHT_YES MODE_NIGHT_NO MODE_NIGHT_FOLLOW_SYSTEM MODE_NIGHT_AUTO_BATTERY • যنѱ • ߋѱ • दझమ ࢸ • ݽ٘ ࢸ • п ࢸী ೧ೞח Night Modeܳ ଵҊೞࣁਃ. = = = = ࢸч द -> light -> dark -> default -> default -
extended Others • WebView + ForceDark • Custom Tabsח Contentী
Force Darkܳ ਗ X • Map stylesب ܻࣗझ۽ ਊೠݶ оמ - res/raw/map_style.json - res/raw-night/map_style.json • Notifications ز ਊ • TextAppearance.Compat.Notification -
extended Elevation • Higher elevation, lighter surface • ߋӝח ߈ైݺೠ
ൟ࢝ overlay۽ ઑ • Elevation (0dp ~ 24dp) • Overlay Transparency (0% ~ 16%) Surface Elevation Overlay -
extended extended • MDC Componentsח ইې ࣘࢿী ٮۄ Elevation Overlaysਸ
ਊೠ. • MaterialShapeDrawable, ElevationOverlayProviderܳ ਊೞݶ Custom Viewী Elevation Overlaysܳ ࣚऔѱ ਊೡ ࣻ . • ਗ ঋח ҃, elevationOverlaysEnabled ࣘࢿਸ false۽ ߸҃ೞݶ ػ. <style name="Theme.MaterialComponents" parent="..."> <item name="elevationOverlaysEnabled">true</item> <item name="elevationOverlaysColor">?attr/colorOnSurface</item> </style> Elevation Overlays E L E V A T I O N -
extended extended MDCীࢲ elevation overlaysо ਊغח Components: • Top App
Bar • Bottom App Bar • Bottom Navigation • Tabs • Card • Dialog • Menu • Bottom Sheet • Navigation Drawer • Switch Elevation Overlays Components E L E V A T I O N -
extended extended ElevationOverlayProvider • Elevationী ٮۄ Overlay ࢚࢝җ ߓ҃࢝ਸ
ࢴযળ. MDC 1.1.0 @ColorInt // layered color, if elevationOverlaysEnabled == true public int layerOverlayIfNeeded(@ColorInt int bgColor, float elevation) @ColorInt // layered color, always public int layerOverlay(@ColorInt int bgColor, float elevation) @ColorInt // layered color, of attr/colorSurface public int getSurfaceColorWithOverlayIfNeeded(float elevation) class -
extended extended MaterialShapeDrawable • MDCীࢲ ߓ҃ী ࢎਊೞҊ ח Drawable •
ղࠗਵ۽ ElevationOverlayProvider ࢎਊ • زਵ۽ Elevation ߸҃ оמ private val bgDrawable = MaterialShapeDrawable().apply { initializeElevationOverlay(context) fillColor = context.getColorAttr(R.attr.colorSurface) } bgDrawable.setElevation(float elevation) class -
extended extended Accessibility #121212 8% Primary Dark Primary #1F1B24 •
MDC Guideline: WCAG’s AA ળࣻܳ ӂ • ఫझ - ୭ࣗ 4.5:1 • ఫझ - ୭ࣗ 3.0:1 • Text, BG р ࠺о ୭ࣗ 15.8:1 ח غযঠ 24dp elevationীࢲ body textо AAܳ ݅ • 24dp = ୭ elevation (MDC) W3C ӂࢎ೦: https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html -
extended Summary • ప݃ ӝמਸ Strongly ӂೠ. •
ప݃ীࢲח -night resource qualifierо ഝࢿചػ. • (Stable ߡ غݶ) AppCompat 1.1.0 / MDC 1.1.0ਸ ࢎਊೞ. • MDC - ప݃ীࢲח Higher elevation, lighter surface! • Accessibility - Text, BG р ࢝ ࠺ܳ Ҋ۰ೞ. -
extended References • Android-DarkTheme https://github.com/googlesamples/android-DarkTheme • MD Dark Theme Guideline
https://material.io/design/color/dark-theme.html https://material.io/develop/android/theming/dark/ • DayNight - Adding a dark theme to your app https://medium.com/androiddevelopers/d10f90c83e94 • IO19 - Dark Theme & Gesture Navigation https://youtu.be/OCHEjeLC_UY • IO19 - How to design a Dark Theme https://youtu.be/9NDLR3COU7Y