首页 > 解决方案 > 将谷歌应用脚​​本文本按钮更改为填充样式

问题描述

默认的文本按钮样式是 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

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

标签: google-apps-scriptenumsgmail-contextual-gadgets

解决方案


对于任何被卡住的人,他们的文档都不清楚这一点,您需要链接方法才能使其正常工作。这是一个工作示例。

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

推荐阅读