

English
listen to system theme state changes.
Related documents: DarkMode Adaptation Guide
Platform Difference Description
App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 抖音小程序 | 飞书小程序 | QQ小程序 | 快手小程序 | 京东小程序 | 元服务 | 小红书小程序 |
---|---|---|---|---|---|---|---|---|---|---|---|
iOS 2.6.5+ 、Android 3.6.9+ | HBuilderX 3.6.9+ | 基础库 2.11.0+ | x | x | x | V5.3.0+ | x | x | x | x | x |
HarmonyOS |
---|
HBuilderX 4.71 |
CALLBACK return parameter
参数 | 类型 | 说明 |
---|---|---|
theme | String | Theme name (dark , light ) |
Example
uni.onThemeChange(function (res) {
console.log(res.theme);
});
Cancel listening to system theme status changes.
Related documents: DarkMode Adaptation Guide
Platform Difference Description
App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 抖音小程序 | 飞书小程序 | QQ小程序 | 快手小程序 | 京东小程序 | 元服务 | 小红书小程序 |
---|---|---|---|---|---|---|---|---|---|---|---|
HBuilderX 3.6.9+ | HBuilderX 3.6.9+ | 基础库 2.11.0+ | x | x | x | V5.3.0+ | x | x | x | x | x |
HarmonyOS |
---|
HBuilderX 4.71 |
parameter
Function CallBack
: The listener function passed in by onThemeChange.
example
const callback = function (res) {
console.log(res.theme);
}
uni.onThemeChange(callback);
uni.offThemeChange(callback); // 此时不再触发 callback 方法
Notice