Class CardHeader
卡片标题
Card
的标头。
适用于 Google Workspace 插件和 Google Chat 应用。
const cardHeader = CardService.newCardHeader()
.setTitle('Card header title')
.setSubtitle('Card header subtitle')
.setImageStyle(CardService.ImageStyle.CIRCLE)
.setImageUrl('https://image.png');
详细文档
setImageAltText(imageAltText)
设置标题图片的替代文本。
参数
名称 | 类型 | 说明 |
imageAltText | String | 标题图片的替代文字。 |
返回
CardHeader
- 此对象,用于链式调用。
setImageStyle(imageStyle)
设置卡片标题中的图标剪裁。默认值为不剪裁。可选。
参数
返回
CardHeader
- 此对象,用于链式调用。
setImageUrl(imageUrl)
通过提供网址或数据字符串来设置要在标头中使用的图片。
提供的网址可以是可公开访问的网址,也可以是 base64 编码的图片字符串。如需获取后者,您可以使用以下代码根据 Google 云端硬盘中的图片创建编码图片字符串,然后存储该字符串以供日后与 setImageUrl(imageUrl)
搭配使用。此方法可让您的插件无需访问公开可用的图片网址:
// The following assumes you have the image to use in Google Drive and have its
// ID.
const imageBytes = DriveApp.getFileById('123abc').getBlob().getBytes();
const encodedImageURL =
`data:image/jpeg;base64,${Utilities.base64Encode(imageBytes)}`;
// You can store encodeImageURL and use it as a parameter to
// CardHeader.setImageUrl(imageUrl).
参数
名称 | 类型 | 说明 |
imageUrl | String | 要使用的托管图片的网址或编码后的图片字符串。 |
返回
CardHeader
- 此对象,用于链式调用。
setSubtitle(subtitle)
设置卡片标题的副标题。可选。
参数
名称 | 类型 | 说明 |
subtitle | String | 标题副标题文字。 |
返回
CardHeader
- 此对象,用于链式调用。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-01-30。
[null,null,["最后更新时间 (UTC):2025-01-30。"],[[["`CardHeader` objects allow you to customize the header of a card, including title, subtitle, and image, within Google Workspace Add-ons and Google Chat apps."],["You can set an image for the header using `setImageUrl()` by providing a public URL or a base64 encoded image string."],["`setTitle()` and `setSubtitle()` allow you to define the main text and supporting text for the header, respectively."],["Customize the image display with `setImageStyle()` to control cropping and use `setImageAltText()` to provide alternative text for accessibility."]]],["The `CardHeader` object allows customization of a card's header in Google Workspace add-ons and Google Chat apps. Key actions include setting the header's title using `setTitle()`, a subtitle with `setSubtitle()`, and an image via `setImageUrl()`. The image's appearance can be modified with `setImageStyle()` for cropping and `setImageAltText()` for alternative text. Image URLs can be direct links or base64 encoded strings. Each method returns the `CardHeader` object, enabling method chaining.\n"]]