app.json
, that means the current mini program has been adapted to DarkMode, all the basic components will display different default styles according to the system theme, and the navigation bar and tab bar will be automatically switched according to the following configuration.app.json
is configured with darkmode
as true
, some of the configuration items of mini program can be configured in the form of variables, defining the colour or icon under different themes in the variable configuration file, as follows:themeLocation
in app.json to specify the path of variable configuration file theme.json, for example: add theme.json
in the root directory, you need to configure "themeLocation": "theme.json"
;@
;theme.json
is used to define the variables related to the colour theme, you need to configure the path of theme.json
in themeLocation
first, otherwise you can't read the variable configuration.Attributes | Type | Required | Descripción |
light | object | yes | Definition of the variable in light mode |
dark | object | yes | Definition of the variable in dark mode |
light
and dark
can define variable names and values as key: value, for example:{"light": {"navBgColor": "#f6f6f6","navTxtStyle": "black"},"dark": {"navBgColor": "#191919","navTxtStyle": "white"}}
@
, for example:// Global Configuration{"window": {"navigationBarBackgroundColor": "@navBgColor","navigationBarTextStyle": "@navTxtStyle"}}// Page Configuration{"navigationBarBackgroundColor": "@navBgColor","navigationBarTextStyle": "@navTxtStyle"}
{"window": {"navigationBarBackgroundColor": "@navBgColor","navigationBarTextStyle": "@navTxtStyle","backgroundColor": "@bgColor","backgroundTextStyle": "@bgTxtStyle","backgroundColorTop": "@bgColorTop","backgroundColorBottom": "@bgColorBottom"},"tabBar": {"color": "@tabFontColor","selectedColor": "@tabSelectedColor","backgroundColor": "@tabBgColor","borderStyle": "@tabBorderStyle","list": [{"iconPath": "@iconPath1","selectedIconPath": "@selectedIconPath1"}, {"iconPath": "@iconPath2","selectedIconPath": "@selectedIconPath2"}]}}
{"light": {"navBgColor": "#f6f6f6","navTxtStyle": "black","bgColor": "#ffffff","bgTxtStyle": "light","bgColorTop": "#eeeeee","bgColorBottom": "#efefef","tabFontColor": "#000000","tabSelectedColor": "#3cc51f","tabBgColor": "#ffffff","tabBorderStyle": "black","iconPath1": "image/icon1_light.png","selectedIconPath1": "image/selected_icon1_light.png","iconPath2": "image/icon2_light.png","selectedIconPath2": "image/selected_icon2_light.png",},"dark": {"navBgColor": "#191919","navTxtStyle": "white","bgColor": "#1f1f1f","bgTxtStyle": "dark","bgColorTop": "#191919","bgColorBottom": "#1f1f1f","tabFontColor": "#ffffff","tabSelectedColor": "#51a937","tabBgColor": "#191919","tabBorderStyle": "white","iconPath1": "image/icon1_dark.png","selectedIconPath1": "image/selected_icon1_dark.png","iconPath2": "image/icon2_dark.png","selectedIconPath2": "image/selected_icon2_dark.png",}}
"darkmode": true
, wx.getSystemInfo
or wx.getSystemInfoSync
will return a theme
attribute with a value of light or dark."darkmode": true
, the theme property is not available (i.e. theme
is undefined
)./* General style begin */.some-background {background: white;}.some-text {color: black;}/* General style end */@media (prefers-color-scheme: dark) {/* Style start under DarkMode */.some-background {background: #1b1b1b;}.some-text {color: #ffffff;}/* Style end under DarkMode */}
本页内容是否解决了您的问题?