# uni.onThemeChange(CALLBACK)

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+ Basic library 2.11.0+ x x x V5.3.0+ x x x

CALLBACK return parameter

Parameter Type Description
theme String Theme name (dark, light)

Example

uni.onThemeChange(function (res) {
	console.log(res.theme);
});

# uni.offThemeChange(CALLBACK)

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+ Basic library 2.11.0+ x x x V5.3.0+ x x x

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

  • Custom base takes effect
  • The dark mode needs to be turned on on the App side. 5+ App [uni-app dark mode](https://uniapp.dcloud.net.cn/tutorial/darkmode.html#open- dark mode)