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/ui/interaction/showToast.md.

showToast

显示 Toast 提示。

扫码预览

扫码预览 showToast

使用限制

WARNING

Android、iOS:Android、iOS 均只按 icon/type 渲染内置图标,不加载 customIcon;依赖 customIcon 展示图标的调用不会生效。

支持版本

前端库版本不低于 0.0.9。

支持平台

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

支持场景

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

使用说明

Android 默认显示 3000 毫秒,iOS 默认显示 2000 毫秒;需要双端一致时请显式传入 duration。

  • message 必填,且 type 与 icon 至少传一个;customIcon 当前不会渲染,请通过 icon 使用内置图标。

调用方式

异步 API

showToast(params: ShowToastParams): Promise<object>

入参

名称类型必填默认值约束说明
customIconstring否--自定义图标的 URL 或 base64 字符串。Android、iOS:Android、iOS 均只按 icon/type 渲染内置图标,不加载 customIcon。
durationnumber否Android 3000,iOS 2000需双端保持一致时请显式传入。提示的持续时间,单位毫秒。
icon"success" | "error" | "warn"否--图标。
messagestring是--提示的内容。
type"default" | "success" | "error" | "warning"否'default'-Toast 的类型。

调用示例

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

// 显示一个成功的 Toast
showToast({
  message: '操作成功',
  type: 'success',
  icon: 'success',
  duration: 1500
}).then(() => {
  console.log('Toast 显示完毕');
});

// 显示一个错误的 Toast
showToast({
  message: '网络错误',
  type: 'error',
  icon: 'error'
});

成功返回

无返回字段。

返回示例

{}

错误处理

错误对象和通用错误码见 通用错误处理。

失败示例

{
  "errNo": 104,
  "errMsg": "invalid parameter"
}

错误码

errNoerrMsg平台触发条件处理建议
104invalid parameterAndroid、iOSmessage 为空;iOS 还会在 icon 取值非法或入参无法解析时返回(type 由前端归一化为合法值,非法 type 场景不会触发)修正参数后重试。
103feature not supportiOS豆包 UIService 未实现,无法展示 Toast降级到其他提示方式。

通用错误码

errNoerrMsg说明平台
102internal error内部错误Android

平台差异

  • iOS:参数校验失败统一返回 errNo 104;UIService 缺失时返回 errNo 103。Android 参数校验失败返回 errNo 104,豆包页面运行上下文缺失返回 errNo 102。