将谷歌应用程序脚本文本按钮更改为填充样式

时间:2021-05-28 01:14:43

标签: google-apps-script enums gmail-contextual-gadgets

默认的文本按钮样式是 TEXT,但如果你想让它有背景,它需要是 FILLED 类型。

const textButton = CardService.newTextButton();
textButton.setText("Update Draft");
textButton.setTextButtonStyle(TextButtonStyle.FILLED);
textButton.setBackgroundColor('#d85300');

此处有问题的行是第三行,即 setTextButtonStyle 方法。 该方法采用 TextButtonStyle 类型的枚举,默认值为 TEXT,但我们需要将其更改为 FILLED,以便我们可以添加背景颜色。

问题是,使用 TextButtonStyle.FILLED 应该可以,这就是您访问枚举值的方式。

这是文档的链接。

https://developers.google.com/apps-script/reference/card-service/text-button#settextbuttonstyletextbuttonstyle

如果您需要更多参考,我正在创建一个 Google Workplace Gmail 插件。

我正在创建一个上下文撰写界面。再次,这是文档。

https://developers.google.com/workspace/add-ons/gmail/extending-compose-ui

当我运行我的应用程序时,出现错误 ReferenceError: TextButtonStyle is not defined

我尝试了几种访问枚举的方法,它应该可以工作,但我不知道为什么不行。

1 个答案:

答案 0 :(得分:0)

对于任何卡住的人,他们的文档对此并不明确,您需要链接方法以使其工作。这是一个工作示例。

const textButton = CardService.newTextButton()
.setText("Update Draft")
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
.setBackgroundColor('#d85300');