Vaadin将组件颜色设置为十六进制、整数或RGB。

huangapple go评论63阅读模式
英文:

Vaadin set component color to hex or int or rgb

问题

我目前正在尝试使用Vaadin。

我看到我可以像这样更改例如按钮的背景颜色:

cButton.getStyle().set("background", "red");

但是如果我想设置一个特定的颜色,就像这个:#EAB251。应该如何完成?

这个颜色可能会根据用户在RGB-/HEX-/INT颜色选择器中的选择而改变。

英文:

I am currently messing about with Vaadin.

I see that that I can change background color of e.g. button like so:

cButton.getStyle().set("background","red");

But if I want to set a specific color like this one: #EAB251. How can it be done?

This color could change depending on what the user chooses in an RGB-/HEX-/INT-color picker.

答案1

得分: 2

你可以为属性使用任何有效的CSS值。因此 cButton.getStyle().set("background", "#EAB251")cButton.getStyle().set("background", "rgb(234, 178, 81)") 应该都可以工作。实际上,你发布的代码行有效,因为 red 是CSS颜色名称之一。

英文:

You can use any valid CSS value for the property. So cButton.getStyle().set("background", "#EAB251") and cButton.getStyle().set("background", "rgb(234, 178, 81)") should work. In fact, the line of code you posted works because red is a CSS color name.

huangapple
  • 本文由 发表于 2020年9月24日 16:59:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/64043008.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定