3

我想使用 .

我可以看到 css 类名被混淆了,但是当我检查 firefox / chrome 中的元素时,类定义没有显示出来。这是我的代码。谁能建议我错过了什么?谢谢。

样式.css

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

资源.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)); 
        } 
4

2 回答 2

7

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

于 2010-11-26T02:57:55.930 回答
2

您需要在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类中填写的属性。请参阅GWT 文档以获取一些指导。

于 2010-11-15T11:05:21.130 回答