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
:這個物件用於鏈結。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-01-30 (世界標準時間)。
[null,null,["上次更新時間: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"]]