gwt - 在 GWT 中需要应用范围的 CSS 常量

标签 gwt uibinder cssresource

我想将一些颜色定义为 GWT CssResource 中的常量,并在整个应用程序中使用这些常量;但我不知道该怎么做。

我会告诉你我尝试了什么。我创建了一个 ClientBundle 和一个 CssResource 如下:

public interface Resources extends ClientBundle {
  public interface MyStyle extends CssResource {
    String JUNGLEGREEN();
    String example();
    ...
  }
  @Source("Resources.css")
  MyStyle css();
}

我已经定义了一些 constants在 Resources.css 中:
@def JUNGLEGREEN #1F3D0A;

在 Resources.css 中,我像这样使用这些常量:
.example { color:JUNGLEGREEN; }

我不知道在其他 CSS 文件和 UiBinder 模板中重用这些常量的方法。我想在其他一些 UiBinder 文件中执行此操作,例如 LoginView.ui.xml:
<ui:with field='resources' type='com.example.Resources' />
<ui:style>
  .mainPanel {
    background:{resources.css.JUNGLEGREEN};
    ...
  }
</ui:style>

...但它似乎没有编译。你知道我怎样才能达到我的目标吗?

最佳答案

这是我们的做法:

  • 我们将所有常量属性放在 constant.css 中文件
  • @def black #241b15;   /* text color */
    @def orange #ff4f00;   /* links */
  • 在每个 ui.xml 文件中,您可以通过以下方式引用这些常量:
  • <ui:style src="../../resources/css/constants.css">
        .myStyle {
            color: orange;
        }
    </ui:style>

    希望有帮助。

    编辑:

    避免<ui:style>中的相对路径元素,您可以执行以下操作:
  • 在 css 文件中再次定义你的常量(比如 constants.css)
  • @def junglegreen #1f3d0a;
  • 创建 ClientBundleCssResource检索定义的常量
  • public interface MyResources extends ClientBundle {
    
        public static final MyResources INSTANCE = GWT.create(MyResources.class);
    
        public interface Constants extends CssResource {
    
            String junglegreen();
        }
    
        Constants constants();
    }

    - 使用 @eval访问常量的注解
    <ui:style>
        @eval green com.gwt.client.widget.test.MyResources.INSTANCE.constants().junglegreen();
    
        .someClass {
            color: green;
        }
    </ui:style>

    我知道如何在不引用 css 文件本身的情况下处理常量的唯一方法。

    关于gwt - 在 GWT 中需要应用范围的 CSS 常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3533211/

    相关文章:

    eclipse - 安装 gwt Eclipse 插件时出现错误 Norepositoryfound contains : osgi.bundle,org

    java - 在 GWT CellTable ImageCell 中显示 base64 编码的图像

    gwt - 获取 UiBinder 小部件以内联显示而不是 block 显示

    css - 与 gwt Uibinder 一起使用带有背景图像集的 css

    java - GXT : Find cell's value in a grid by coordinates

    events - GWT eventbus 处理多个模块

    gwt - 如何在 gwt ui.xml 中将一个页面包含在另一页面中

    java - GWT HTMLPanel UiBinder XML 的规范在哪里?

    css - GWT css 背景图片

    java - 如何从 CSS 访问样式