Class IconImage
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
图标图片
预定义图标、Material Design 图标,或具有可自定义剪裁样式的网址图标。
详细文档
setAltText(altText)
设置网址的替代文本,用于无障碍功能。
参数
名称 | 类型 | 说明 |
altText | String | 替代文本。 |
返回
IconImage
- 此对象,用于链式调用。
setIcon(icon)
如果未设置网址,则设置预定义的图标。默认值为 NONE。
参数
返回
IconImage
- 此对象,用于链式调用。
setIconUrl(url)
如果未设置图标,则设置图标的网址。
参数
名称 | 类型 | 说明 |
url | String | 要用作图标的托管图片的网址。 |
返回
IconImage
- 此对象,用于链式调用。
setImageCropType(imageCropType)
设置图片的剪裁样式。您可以为图标使用的剪裁类型选项包括 SQUARE
和 CIRCLE
。默认值为 SQUARE
。
参数
返回
IconImage
- 此对象,用于链式调用。
setMaterialIcon(icon)
设置 Material Design 图标。
const iconImage = CardService.newIconImage().setMaterialIcon(
CardService.newMaterialIcon().setName('search'),
);
参数
返回
IconImage
- 此对象,用于链式调用。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eIconImage\u003c/code\u003e allows you to display a predefined or custom icon using a URL.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize the icon's appearance with a specific crop style (SQUARE or CIRCLE).\u003c/p\u003e\n"],["\u003cp\u003eAlternative text can be set for accessibility purposes using \u003ccode\u003esetAltText()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003esetIcon()\u003c/code\u003e and \u003ccode\u003esetIconUrl()\u003c/code\u003e methods allow you to specify the icon source, either a predefined icon or a URL.\u003c/p\u003e\n"],["\u003cp\u003eAll methods return the \u003ccode\u003eIconImage\u003c/code\u003e object, enabling method chaining for streamlined configuration.\u003c/p\u003e\n"]]],["The `IconImage` object allows setting an icon using predefined options, a material design icon, or a URL. Key actions include: setting alternative text for accessibility (`setAltText`), choosing a predefined icon (`setIcon`), specifying an icon URL (`setIconUrl`), defining the image crop style (`setImageCropType`), and selecting a material design icon (`setMaterialIcon`). Each method returns the `IconImage` object for chaining additional actions.\n"],null,["# Class IconImage\n\nIconImage\n\nA predefined icon, a material design icon, or an icon from a URL with a customizable crop style. \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------------------------------------------------|----------------|-----------------------------------------------------------------------|\n| [setAltText(altText)](#setAltText(String)) | [IconImage](#) | Sets the alternative text of the URL which is used for accessibility. |\n| [setIcon(icon)](#setIcon(Icon)) | [IconImage](#) | Sets the predefined icon if the URL is not set. |\n| [setIconUrl(url)](#setIconUrl(String)) | [IconImage](#) | Sets the URL of the icon if the icon is not set. |\n| [setImageCropType(imageCropType)](#setImageCropType(ImageCropType)) | [IconImage](#) | Sets the crop style for the image. |\n| [setMaterialIcon(icon)](#setMaterialIcon(MaterialIcon)) | [IconImage](#) | Sets the material design icon. |\n\nDetailed documentation\n----------------------\n\n### `set``Alt``Text(altText)`\n\nSets the alternative text of the URL which is used for accessibility.\n\n#### Parameters\n\n| Name | Type | Description |\n|-------------|----------|-----------------------|\n| `alt``Text` | `String` | The alternative text. |\n\n#### Return\n\n\n[IconImage](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Icon(icon)`\n\nSets the predefined icon if the URL is not set. Default is NONE.\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|--------------------------------------------------|--------------------------------------------------------------------------------|\n| `icon` | [Icon](/apps-script/reference/card-service/icon) | One of the predefined [Icon](/apps-script/reference/card-service/icon) values. |\n\n#### Return\n\n\n[IconImage](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Icon``Url(url)`\n\nSets the URL of the icon if the icon is not set.\n\n#### Parameters\n\n| Name | Type | Description |\n|-------|----------|------------------------------------------------------|\n| `url` | `String` | The URL address of a hosted image to use as an icon. |\n\n#### Return\n\n\n[IconImage](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Image``Crop``Type(imageCropType)`\n\nSets the crop style for the image. The crop type options you can use for icons are `SQUARE\n` and `CIRCLE`. Default is `SQUARE`.\n\n#### Parameters\n\n| Name | Type | Description |\n|---------------------|----------------------------------------------------------------------|------------------------------------|\n| `image``Crop``Type` | [ImageCropType](/apps-script/reference/card-service/image-crop-type) | The ImageCropType option to apply. |\n\n#### Return\n\n\n[IconImage](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Material``Icon(icon)`\n\nSets the material design icon.\n\n```javascript\nconst iconImage = CardService.newIconImage().setMaterialIcon(\n CardService.newMaterialIcon().setName('search'),\n);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|-------------------------------------------------------------------|--------------------|\n| `icon` | [MaterialIcon](/apps-script/reference/card-service/material-icon) | The material icon. |\n\n#### Return\n\n\n[IconImage](#) --- This object, for chaining."]]