[英]Android Colors in Dark Mode
在res/values/colors
有两个colors
colors.xml
colors.xml(night)
如果夜晚不存在,您可以如下制作:
右键单击values
文件夹。
下一个New
。 然后Values Resource file
在file name
段中输入colors
并在directory name
字段中输入values-night
。
在 colors.xml、select 中,Z62848E3CE5804AA985513A7922FF8 为:
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryVariant">#303F9F</color>
<color name="colorButton">#303F9F</color>
在 colors.xml(night) 中,将 colors 设置为夜间(与颜色同名):
<color name="colorPrimary">#212121</color>
<color name="colorPrimaryVariant">#000000</color>
<color name="colorButton">#10ffffff</color>
现在如果在布局中,例如:
<Button
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: background = "@color/colorButton" />
是根据你在光与夜colors中放入什么来选择的。
https://developer.android.com/guide/topics/resources/providing-resources
使用文件夹:
/values/
/values-night/
它在这里也提到了它: https://developer.android.com/guide/topics/ui/look-and-feel/darktheme#config-changes
“夜间限定资源”
Your themes and styles should avoid hard-coded colors or icons intended for use under a light theme. You should use theme attributes (preferred) or night-qualified resources instead.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.