Google幻灯片API,可以用十六进制设置颜色吗?

Google Slides API, able to use Hexadecimal to set Colors?

是否可以使用十六进制格式设置元素形状背景颜色,例如#B6D7A8?我在这里看到一个例子, Google Slides API- How to change text color for all shapes of a certain color

但是,Google 幻灯片 API 参考文献中没有提到它。我想确定一下,专门针对 Java 环境。

https://developers.google.com/slides/reference/rest/v1/presentations.pages/other#Page.OpaqueColor

    requests.add(new Request()
            .setUpdateShapeProperties(new UpdateShapePropertiesRequest()
                .setObjectId(elementRandomString)
                    .setShapeProperties(new ShapeProperties()
                            .setShapeBackgroundFill(new ShapeBackgroundFill()
                                .setSolidFill(new SolidFill()
                                        .setColor(new Col)

答案在post Google Slides API- How to change text color for all shapes of a certain color uses Slide Service Apps Script中设置颜色。

回答你的问题,无法以十六进制格式设置颜色。 如您提供的参考文档中所述,您需要提供一个 RgbColor object in your OpaqueColor.

解决方法:

  1. 将您的十六进制颜色转换为 RGB 然后将 redbluegreen 值除以 255 以获得接受的 RgbColor值为 0.0 ~ 1.0

您可能希望将此作为参考:java :

  1. 根据您转换后的 redbluegreen 值设置 RgbColor

示例代码:

requests.add(new Request()
            .setUpdateShapeProperties(new UpdateShapePropertiesRequest()
                .setObjectId(elementRandomString)
                    .setShapeProperties(new ShapeProperties()
                            .setShapeBackgroundFill(new ShapeBackgroundFill()
                                .setSolidFill(new SolidFill()
                                        .setColor(new Color()
                                                .setRgbColor(new RgbColor()
                                                      .setRed(redFloatValue)
                                                      .setBlue(blueFloatValue)
                                                      .setGreen(greenFloatValue))))))));

参考文献: