Gwt ui:使用,样式不显示

Gwt ui:使用,样式不显示,gwt,uibinder,Gwt,Uibinder,我想使用多个小部件共享CSS 我可以看到css类名是模糊的,但是类定义 在我检查firefox/chrome中的元素时没有显示。 这是我的密码。有人能告诉我我错过了什么吗?谢谢 Style.css .nameSpan { color: #3E6D8E; background-color: #E0EAF1;} Resources.java public interface Resources extends ClientBundle { @Source("Style.css")

我想使用多个小部件共享CSS

我可以看到css类名是模糊的,但是类定义 在我检查firefox/chrome中的元素时没有显示。 这是我的密码。有人能告诉我我错过了什么吗?谢谢

Style.css

.nameSpan {  color: #3E6D8E; background-color: #E0EAF1;} 
Resources.java

public interface Resources extends ClientBundle { 
  @Source("Style.css") 
  Style style(); 
  public interface Style extends CssResource { 
    String nameSpan(); 
  } 
} 
uibinder.ui.xml

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' 
    xmlns:g='urn:import:com.google.gwt.user.client.ui'> 
  <ui:with field='res' type='com.my.app.widgets.logoname.Resources'/> 
  <g:HTMLPanel> 
      <div> 
        Well hello there 
        <g:InlineLabel ui:field='nameSpan' styleName="res.style.nameSpan">kevin</g:InlineLabel>
      </div> 
  </g:HTMLPanel> 
</ui:UiBinder> 

你好
凯文
uibinder.class

public class uibinder extends Composite { 
        private static uibinderUiBinder uiBinder =     GWT.create(uibinderUiBinder.class); 
        interface uibinderUiBinder extends UiBinder<Widget, uibinder> {} 
        @UiField(provided = true)  final Resources res;  // the style doesn't show no matter provided=true is declared or not. 
        public uibinder(Resources res) { 
                res = GWT.create(Resources.class); 
                initWidget(uiBinder.createAndBindUi(this)); 
        } 
公共类uibinder扩展了复合{
私有静态uibinderUiBinder=GWT.create(uibinderUiBinder.class);
接口uibinderUiBinder扩展了UiBinder{}
@UiField(provided=true)final Resources res;//无论是否声明provided=true,样式都不会显示。
公共图书馆(资源库){
res=GWT.create(Resources.class);
initWidget(uiBinder.createAndBindUi(this));
} 

您需要在某个地方指定样式(
styleName
属性)。例如:

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui'> 
    <ui:with field='res' type='com.my.app.widgets.logoname.Resources'/> 
    <g:HTMLPanel> 
        <div> 
            Well hello there 
            <g:InlineLabel ui:field='nameSpan' styleName="{res.nameSpan}">kevin</g:InlineLabel>
        </div> 
    </g:HTMLPanel> 
</ui:UiBinder>

你好
凯文

您声明的属性
ui:field
没有设置css样式。它定义了要在
uibinder
类中填充的属性。有关一些指导,请参阅。

您必须使用
res.style().ensureInjected()

并且不要忘记调用:
res.style().ensureInjected()是的,这是解决方案!!!谢谢。你应该把它作为答案,我会接受的!事实上,我确实添加了样式名,但样式没有显示。我编辑了问题以反映更改。在这种情况下,你可能需要检查z00bs代码段中的花括号是否也存在于你的代码中。Hilbrand已经提到了是的,但答案是肯定的。