我有一个像这样的 uiBinder 设置:
<ui:style field="localStyle">
.action {
background-color: #529412;
height: 28px;
width: 100%;
}
.action > table {
height: 100%;
width: 100%;
}
.action a {
font-size: 14px;
color: white;
text-decoration: none;
}
</ui:style>
<g:FlowPanel>
<g:SimplePanel ui:field='action' styleName='{localStyle.action}'>
<g:HorizontalPanel>
<g:Cell verticalAlignment="MIDDLE" horizontalAlignment="LEFT">
<g:SimplePanel ui:field='navigations' styleName='{localStyle.navigations}'></g:SimplePanel>
</g:Cell>
<g:Cell verticalAlignment="MIDDLE" horizontalAlignment="RIGHT">
<g:SimplePanel ui:field='actions' styleName='{localStyle.actions}'></g:SimplePanel>
</g:Cell>
</g:HorizontalPanel>
</g:SimplePanel>
<g:SimplePanel ui:field='content'>
</g:SimplePanel>
</g:FlowPanel>
但我在那个 uifield:action 中设置了一个 MenuBar,代码如下:
private MenuBar createMenuBar(){
MenuBar menuButton = new MenuBar();
MenuBar mb = new MenuBar(true);
mb.addItem(getAboutMenuItem());
mb.addItem(getLogoutMenuItem());
return menuButton;
}
当我想设置 MenuBar 的颜色样式时,我该怎么做......我已经试过了
.actions MenuBar {
background-color: #eee;
}
但它不喜欢那样。有什么建议吗?
最佳答案
您不能通过 CSS 中的类名访问 GWT 小部件。
你必须在你的 Ui:Binder CSS 中创建一个类名
.menuBar {/* STYLE */}
然后按照官方文档中的说明将样式注入(inject)到您的 Java 类中: http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html#Programmatic_access
然后您可以在您的 Java 类中访问样式并执行
mb.addStyleName(css.menuBar);
关于java - 通过 uiBinder - GWT 从 Panel 更改 MenuBar 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24555473/