You can reference the style, which you have declared in UiBinder. But you need to take some additional steps. Look at this example:
UiBinder
<!-- (1) declare your style , remember to set the type attribute correctly - you should place your package.WidgetName.StyleName in there -->
<ui:style type='z.client.TEstWidget.MyStyle'>
.blackBG {
background-color: black;
}
.grayBG {
background-color: gray;
}
</ui:style>
<g:HTMLPanel>
<g:Label ui:field="myLabel" styleName="{style.grayBG}">test</g:Label>
<g:Button ui:field="myButton">change style</g:Button>
</g:HTMLPanel>
Widget code
public class TEstWidget extends Composite {
private static TEstUiBinder uiBinder = GWT.create(TEstUiBinder.class);
interface TEstUiBinder extends UiBinder<Widget, TEstWidget> {
}
// declare the style (2)
interface MyStyle extends CssResource {
String blackBG();
String grayBG();
}
// (3) here you make reference to the style declared in uibinder
@UiField
MyStyle style;
@UiField
Button myButton;
@UiField
Label myLabel;
public TEstWidget() {
initWidget(uiBinder.createAndBindUi(this));
}
@UiHandler("myButton")
public void onClick(ClickEvent event) {
// change the background of the label
// (4) this is how you can use your style
myLabel.removeStyleName( style.grayBG());
myLabel.addStyleName(style.blackBG());
}
}