css - 使用@sprite 从外部 CSS 文件附加 ImageResource

标签 css gwt sprite cssresource clientbundle

我正在尝试在 GWT2.2 元素中同时使用 CssResource 和 ImageResource。

CssResource 和混淆工作正常,但我在访问图像时遇到问题。

我已经可以通过以下方式直接从 ui.xml 文件中通过 ImageResource 访问图像:

<ui:with type="com.example.client.resource.ResourceBundle" field="myResource"/>
<g:Image resource="{myResource.image}"/>

但我无法使用@sprite 从外部 .css 文件中附加 ImageResource。

我有以下接口(interface):

public interface ResourceBundle extends ClientBundle {
ResourceBundle INSTANCE = GWT.create (ResourceBundle.class);

    @Source("com/example/client/resource/images/image.png")
    ImageResource image();

    @Source("com/example/client/resource/css/mystyle.css")
    MyCssResource myCssResource();
    }

public interface MyCssResource extends CssResource {
    String className();
}

当我将 Sprite 添加到 css 文件时,

@sprite .className {
    gwt-image: 'image';
}

我收到以下错误信息:

[ERROR] - Unable to find ImageResource method value("image") in
com.example.client.views.MyView_BinderImpl_GenBundle : Could not find 
no-arg method named image in type com.example.views.MyView_BinderImpl_GenBundle

最佳答案

您可以按如下方式从 UiBinder 模板访问您的样式:

<ui:with type="com.example.client.resource.ResourceBundle" field="myResource"/>

<g:FlowPanel styleName="{myResource.myCssResource.className}"/>

关于css - 使用@sprite 从外部 CSS 文件附加 ImageResource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5546782/

相关文章:

css - 将元素的底部边缘定位在容器内

html - Flex basis 100% in column flexbox : full height in Firefox, not in Chrome

GWT:如何更改 GWT Celltable 中的行颜色

java - 如何在Project POM中继承External Maven POM

gwt - Gwt 中 Html***Builder 和 Dom***Builder 类的区别

typescript - 移相器 3 : Update Sprite object from canvas texture

CSS 背景图像未固定

CSS 包裹不同尺寸的 div

python - 区分组中的对象

python - 如何在pygame中按下按键后更改屏幕上的 Sprite