各位开发者您好。
我已经使用Android Studio开发了 Android App ,但我只考虑了轻模式的布局主题。这是它的外观:
所以现在,当我将手机切换到暗模式时,会发生这种情况:
如何更改在暗模式下显示的颜色?
各位开发者您好。
我已经使用Android Studio开发了 Android App ,但我只考虑了轻模式的布局主题。这是它的外观:
所以现在,当我将手机切换到暗模式时,会发生这种情况:
如何更改在暗模式下显示的颜色?
在res/values/colors
有两种颜色
colors.xml
colors.xml(night)
__
如果不存在夜晚,可以如下制作:
右键单击values
文件夹。
接下来New
。然后 在字段中Values Resource file
输入并在字段中
输入。
__
在colors.xml 中,选择灯光的颜色,例如:colors
file name
values-night
directory name
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryVariant">#303F9F</color>
<color name="colorButton">#303F9F</color>
在 colors.xml(night) 中,设置夜晚的颜色(与颜色同名):
<color name="colorPrimary">#212121</color> <!--actionBarColor-->
<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" />
它是根据您在灯光和夜间颜色中添加的内容来选择的。
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.