2013-04-17 41 views
3

在下面的例子中,從文件MessageView.ui.xml:我可以使用UiBinder的樣式定義變量GWT

<ui:style> 
    .polite { 
     position:fixed; 
     background-color:notice-background-color; 
     top:1em; 
     left:2em; 
     white-space:nowrap; 
     border-radius:.5em;} 
</ui:style> 

<g:PopupPanel styleName="{style.polite}"> 
    <g:HTML ui:field="message">Message goes here.</g:HTML> 
</g:PopupPanel> 

我可以定義@通知,背景顏色,使得其他UiBinder的文件也可以使用定義。

回答

3

是的,你可以。定義你的顏色爲靜態String

package com.myproject.client.resource; 

public class MyColors { 
    public static String lightGreen = "#0bdc1a"; 
} 

,並定義一個變量@eval

<ui:style> 
    @eval notice-background-color com.myproject.client.resource.MyColors.lightGreen; 

    .polite { 
     position:fixed; 
     background-color:notice-background-color; 
     top:1em; 
     left:2em; 
     white-space:nowrap; 
     border-radius:.5em;} 
</ui:style> 

<g:PopupPanel styleName="{style.polite}"> 
    <g:HTML ui:field="message">Message goes here.</g:HTML> 
</g:PopupPanel> 
+0

這應該做的伎倆,這裏是一個參考:https://code.google.com/p/ google-web-toolkit/wiki/CssResource#常量 –

+0

很棒。我明天會實施這個。你知道我可以從我的一般.css文件訪問這個.lightGreen嗎?然後我會在一個地方定義所有這些定義。 – Carl

+0

太棒了。並且可以在應用程序的.css文件中使用相同的方法。在.css文件中,在css定義中使用lightGreen之前添加相同的@eval。 – Carl