如何使用新的DayNight主题? [英] How to use the new DayNight Theme?

查看:269
本文介绍了如何使用新的DayNight主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始接触Google支持库的新更新,我想在我的应用程序中实现Theme.AppCompat.DayNight.
我遇到的问题是似乎没人解释如何自定义它.因此,如果我想白天使用不同的colorAccent,晚上使用不同的colorAccent,该怎么做?您是否应该指定不同的深色和浅色主题作为基础?预先感谢!

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 am having is that it seems no one explained how to customize it. So If I want to have a different colorAccent for day and a different one for night, how do I do that? Are you supposed to specify different dark and light themes to base off of? Thanks in advance!

推荐答案

您可以使用

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).

限定词:
night:夜间
notnight:白天时间

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>

具有 AppCompat 主题:

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

然后在您的应用程序主题中定义参考颜色资源,并在需要时在values-night目录中覆盖值:

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

示例:res\values\colors.xml:

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

res\values-night\colors.xml文件夹中定义相同的颜色:

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

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

这篇关于如何使用新的DayNight主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆