How to use the new DayNight Theme?

前端 未结 1 1130
忘了有多久
忘了有多久 2020-12-29 07:59

Starting to get my hands into that new update to the Google Support Library and I want to implement the Theme.AppCompat.DayNight into my app.
The problem I

相关标签:
1条回答
  • 2020-12-29 08:34

    You can use the night resource qualifier folder.
    In this way you can define colors and the other resources for the dark (night) and for the light theme (day).

    Qualifiers:
    night: Night time
    notnight: Day time

    In order to support the dark theme with a Material Components Theme use:

    <style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
        <!-- ... -->
    </style>
    

    With an AppCompat theme:

      <style name="AppTheme" parent="Theme.AppCompat.DayNight">
          <item name="colorPrimary">@color/primary</item>
       </style>
    

    Then define in your app theme the references color resources, and override the value in the values-night directory if needed:

    Example: res\values\colors.xml:

       <color name="colorPrimary">.....</color>
    

    In res\values-night\colors.xml folders define the same color:

       <color name="colorPrimary">.....</color>
    
    0 讨论(0)
提交回复
热议问题