-
Notifications
You must be signed in to change notification settings - Fork 0
How to use day Night Theme ?
Devrath edited this page May 28, 2021
·
1 revision
If we want to support dark theme
on android-10 & above
, pre android
devices we need to use via day-night theme
- The
androidX
AppCompact
library has aDayNight theme
calledTheme.AppCompat.DayNight
- In the
res/values/styles.xml
<style name="Theme.AppCompat.DayNight" parent="Theme.AppCompat.Light">
- In the
res/values-night/styles.xml
<style name="Theme.AppCompat.DayNight" parent="Theme.AppCompat">
- Styles implemented as
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompact.DayNight">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:forceDarkAllowed">true</item>
</style>
- The Material component library also has theme support supporting both day and night types.
- Advantage of using the
MaterialComponents
is the appearance that looks more stylish and modern which users might expect from a modern android application. - For this we need to use
implementation 'com.google.android.material:material:1.4.0-beta01'
- Styles added as
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:forceDarkAllowed">true</item>
</style>