如何使用新的DayNight主题?

时间:2016-02-25 14:10:47

标签: android android-support-library android-appcompat android-theme

开始接触Google支持库的新更新,我想在我的应用中实施Theme.AppCompat.DayNight
我遇到的问题是,似乎没有人解释如何自定义它。所以,如果我想在一天中使用不同的colorAccent而在夜晚使用不同的try { # Assumes no Q:\ drive connected. $foo = Get-PSDrive -name 'Q' -ErrorAction Stop } # Catch exceptions thrown by both v2.0 and by later versions. catch [System.Management.Automation.ActionPreferenceStopException], ` [System.Management.Automation.DriveNotFoundException] { Write-Output "Drive not found." } catch { Write-Output "Something else went wrong." } ,我该怎么做?你应该指定不同的黑暗和光明主题吗?提前谢谢!

1 个答案:

答案 0 :(得分:31)

您可以使用night resource qualifier folder 通过这种方式,您可以为夜晚和白天定义颜色和其他资源。

<强>限定符:
night:夜间
notnight:白天时间

示例:

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

values-nightvalues-notnight文件夹中定义您的颜色:

<color name="primary">XXXX</color>

注意official post

  

请考虑使用标准颜色或利用AppCompat中的着色支持来更轻松地支持此模式。

相关问题