首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ClientBundle图像作为背景图像

使用ClientBundle图像作为背景图像
EN

Stack Overflow用户
提问于 2011-03-18 23:39:00
回答 2查看 8.5K关注 0票数 9

我尝试在UIBInder模板中使用来自ClientBundle的图像作为背景图像。我使用this discussion作为指南,但无法使其正常工作。

在我的Java类中,我有:

代码语言:javascript
复制
public static interface PriceButtonStyles extends ClientBundle
{
    String paidIcon();

    @ClientBundle.Source("paid_button_53x31.png")
    DataResource paid_buttonAsDataResource();
}

@UiField
PriceButtonStyles priceButtonStyle;

然后在相应的模板文件中,我像这样引用它:

代码语言:javascript
复制
<ui:style field="priceButtonStyle" type="com.example.client.PriceButton.PriceButtonStyles">

    @url paidIconUrl paid_buttonAsDataResource;

    .paidIcon {
        background: paidIconUrl 0 0 no-repeat;

    }
</ui:style>

在这一点上,我的集成开发环境已经用红色显示了"paidIconUrl“字符串,这表明有些地方不太正确:

事实上,当我尝试运行它时,我得到了:

代码语言:javascript
复制
    ERROR: Type com.ecample.client.PriceButton.PriceButtonStyles does not extend com.google.gwt.resources.client.CssResource Element <ui:style field='priceButtonStyle' type='com.example.client.PriceButton.PriceButtonStyles'> (:7). 
ERROR: Uncaught exception escaped. com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses

在进一步的Google Groups discussion中,有人建议这可能与<ui:data>而不是<ui:style>一起工作,所以我试着让它工作。但是似乎你不能在<ui:data>资源中同时包含CSS样式(例如,我的paidIcon()方法)和DataResources。我找不到很多关于<ui:data>的文档,所以我真的只是在摸索这方面的经验。

EN

回答 2

Stack Overflow用户

发布于 2012-03-29 17:14:30

除了要在其中设置src属性的图像之外,还必须设置

代码语言:javascript
复制
<g:Image url="{res.minimize.getSafeUri.asString}" ....>

res的实例化方式如下:

代码语言:javascript
复制
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<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="xxx.myRes"></ui:with>
....

客户端包看起来像这样:

代码语言:javascript
复制
package xxx;

import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;

public interface myRes extends ClientBundle {

    @Source("minimize.png")
    ImageResource minimize();

}

在我的例子中,创建ClientBundle (例如使用GWT.<TitleBarBundle>create(myRes.class);)是不必要的。

谢谢你的回答,Chris Boesing,但我觉得我也必须和你分享我的经验。

向你致敬,斯特凡

票数 7
EN

Stack Overflow用户

发布于 2011-03-19 00:26:42

这就是我是怎么做的。这与你的方法有点不同,但在这种情况下对我来说很有效。您的ClientBundle将如下所示:

代码语言:javascript
复制
public static interface PriceButtonStyles extends ClientBundle
{
     @Source("PriceButtonStyles.css")
     Styles priceButtonStyles();

     @Source("paid_button_53x31.png")
     ImageResource paidButtonPNG();

     interface Styles extends CssResource {
         String buttonBackground();
     }
}

然后,您需要第一个@Source中的PriceButtonStyles.css

代码语言:javascript
复制
.buttonBackground {
    gwt-image:'paidButtonPNG';
    background-repeat:no-repeat;
}

您的*.ui.xml将如下所示:

代码语言:javascript
复制
<ui:with field="res" type="com.ecample.client.PriceButton.PriceButtonStyles"></ui:with>
<g:Label styleName="{res.priceButtonStyles.buttonBackground}"><g:Label>

即使您的样式在css文件中,它仍然会被编译器最小化和混淆。

编辑:别忘了调用

GWT.<PriceButtonStyles> create(PriceButtonStyles.class).priceButtonStyles().ensureInjected(); 的最佳位置是您的EntryPoint method

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5354347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档