For AI agents: the complete documentation index is available at /apps-plugin/docs/llms.txt, the full documentation bundle is available at /apps-plugin/docs/llms-full.txt, and this page is available as Markdown at /apps-plugin/docs/js-api/basic/system/onThemeChange.md.

onThemeChange

监听应用主题变化。

当用户在系统设置或豆包客户端内切换浅色、深色主题时触发。回调参数中的 theme 表示切换后的主题,可与 getAppBaseInfo 返回的 theme 字段配合使用。

扫码预览

扫码预览 onThemeChange

支持版本

前端库版本不低于 0.0.32。

支持平台

平台支持情况
Android支持
iOS支持
PC不支持
HarmonyOS不支持

支持场景

场景支持情况
页面支持
卡片支持

使用说明

  • 调用返回的取消函数即可移除该监听;可与 getAppBaseInfo 返回的 theme 字段配合使用。

调用方式

事件监听 API

onThemeChange(callback: ThemeChangeListener): () => void

入参

无。

调用示例

import { onThemeChange } from '@doubao-dev/framework/api';

const offThemeChange = onThemeChange(({ theme }) => {
  console.log('当前主题:', theme);
});

offThemeChange();

回调参数

名称类型必返说明
event.themeAppTheme是切换后的应用主题

返回值

返回取消当前监听函数的函数。

回调示例

{
  "theme": "dark"
}

平台差异

  • Android:部分豆包 Android 版本可能不会触发主题变化事件