How to declare dependent style names with UiBinder

后端 未结 6 1743
攒了一身酷
攒了一身酷 2020-12-05 02:38

I have a simple UiBinder widget containing a TextArea:




        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 03:08

    Why don't you try sth like this

    public class MyFoo extends Widget {
      interface MyStyle extends CssResource {
        String normal();
        String readonly();
      }
    
      @UiField MyStyle style;
    
      /* ... */
    
      void setEnabled(boolean enabled) {
        getElement().addStyle(enabled ? style.normal() : style.readonly());
        getElement().removeStyle(enabled ? style.readonly() : style.normal());
      }
    }
    

    this would allow you change style if a text box is "normal" or readonly...

    And off course, in the UiBinder you should have sth like

    
    
      
        .redBox { background-color:pink; border: 1px solid red; }
        .normal { color:black; }
        .readonly { color:gray; }
      
    
      
    I'm a red box widget.

提交回复
热议问题