以编程方式将 UiBinder 样式更改为另一个 UiBinder 样式
简单的例子。我在 UiBinder 中声明了 2 种样式:
<ui:style>
.success {
font-size: 13px;
margin: 15px;
font-weight: bold;
display: inline;
padding: 3px 7px;
background: #FFF1A8;
}
.error {
font-size: 13px;
margin: 15px;
font-weight: bold;
display: inline;
padding: 3px 7px;
background: #990000;
color: #fff;
}
</ui:style>
我还有一个标签,也应用了其中一种样式。
<g:Label ui:field="statusLabel" styleName='{style.success}' />
在 UiBinder 中,有没有一种方法可以让我以编程方式将样式切换到错误样式?很高兴能够在小部件中组织我的 CSS,但我还没有找到另一种组织它的好方法。
如果我所要求的不可能,我应该如何在 gwt 中组织我的 CSS,这样我就不会得到大量的样式,而且也很简单、可用?我想有一种聪明的方法可以使用 ClientBundle 来实现此目的,但我还没有弄清楚。我还认为,通过将所有内容保留在 UiBinder 中而不弄乱另一个文件,能够更方便地执行上述方式。不管怎样,请在事情失控之前帮助我!
Simple example. I have 2 styles declared in UiBinder:
<ui:style>
.success {
font-size: 13px;
margin: 15px;
font-weight: bold;
display: inline;
padding: 3px 7px;
background: #FFF1A8;
}
.error {
font-size: 13px;
margin: 15px;
font-weight: bold;
display: inline;
padding: 3px 7px;
background: #990000;
color: #fff;
}
</ui:style>
I also have a label that one of them is applied too.
<g:Label ui:field="statusLabel" styleName='{style.success}' />
Within UiBinder, is there a way that I would be able to go about programatically switching the style to the error style? It's nice being able to organize my CSS right there in the widget, and I haven't found another good way of organizing it.
If what I'm asking isn't possible, how should I be organizing my CSS in gwt, so that I don't end up with a giant pool of styles, and is also easy, and usable? I imagine there is a smart way to use a ClientBundle for this, but I haven't figured it out. I also think it'd be more convenient to be able to do the above mentioned way by just keeping everything in UiBinder without messing with another file. Either way, please help me before this gets out of hand!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您必须在代码隐藏文件中执行此操作。可以在此处找到说明:
以编程方式访问内联样式。
下面是一个示例:
testBinder.ui.xml
testBinder.java
如果单击此按钮,您可以看到它的样式根据 UiBinder 文件中的 CSS 定义而变化。 (在这种情况下,签证诗句从黑色切换到灰色)
Yes, you have to do it in you code behind file. A description can be found here:
Programmatic access to inline Styles.
Here is an example:
testBinder.ui.xml
testBinder.java
If you click this button, you can see the it's style changing according to your CSS definition in your UiBinder file. (In this case switching from black to gray an visa verse)