繁体   English   中英

Android Colors 在暗模式下

[英]Android Colors in Dark Mode

各位开发者您好。

我已经使用Android Studio开发了 Android 应用程序,但我只考虑了灯光模式的布局主题。 这是它的外观:

灯光模式

所以现在,当我将手机切换到模式时,会发生这种情况:

黑暗模式

如何更改在暗模式下显示的 colors ?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM