if I want to programmatical...">

Use uibinder css in java, not in xml

in my ui.xml, I have a style as below

<ui:style src="../teststyle.css" />

if I want to programmatically use a style inside a java file, not ui.xml , in my widget how to call .setStyleName (..), since css is confused

+3
source share
2 answers

You need to take the following steps to use styles in the view class:

  • Define an interface that extends CssResourcein the view class
interface Style extends CssResource {

    String myStyle();

}
  • Add the ui field of this type that you just defined in the view class
@UiField
Style style;
  • In your ui.xml add an attribute typeto the element <ui:style>(the type must match the interface of step 1):
<ui:style type="com.example.MyView.Style">
  • css, , Style ( myStyle())

  • Style (style.myStyle())

, .

+14

, , CssResource (, , ). , ( cssInstance). cssInstance.ensureInjected(). , : : anyWidget.addStyleName(cssInstance.styleBorder());

+2

Source: https://habr.com/ru/post/1770543/


All Articles