1

我正在尝试在 CSS 中使用使用 Client Bundle 加载的图像,所以我使用 CssResource 编码如下,对我不起作用

ClientBundle 接口

public interface MyResources extends ClientBundle {
      @Source("tab_off_LT.png")
      DataResource image();

      @Source("my.css")
      MyCssResources css();
    }

Css资源接口

public interface MyCssResources extends CssResource{

    String myImage();
}

CSS 文件

@url test1 image;
.myImage {
  background: 'test1';
  width: 50px;
}

实现代码

RootLayoutPanel rp = RootLayoutPanel.get();
MyResources myr = (MyResources) GWT.create(MyResources.class);
myr.css().ensureInjected();
Label l = new Label("Test BackgroundImage");
l.setStyleName(myr.css().myImage());
rp.add(l);

如果我在代码中的任何地方出错,请纠正我,想知道哪里出错了吗?

4

1 回答 1

2

@url定义一个变量(在您的情况下名为test1)。代码中的值background是字符串文字,而不是对变量的引用:删除引号。

@url test1 image;
.myImage {
   background: test1;
   width: 50px;
}

请参阅https://developers.google.com/web-toolkit/doc/latest/DevGuideClientBundle#References_to_Data_Resources

于 2012-11-17T10:26:55.507 回答