我有一个 DatePicker 小部件,我需要为其应用自定义样式。为了实现它,我所做的是,在应用程序主 css 文件中,我添加了如下 css 样式
.dRPLable {
font-size: 10px;
font-weight: bold;
color: gray;
}
.dRPBtn {
background-color: #38B0DE;
background: #38B0DE;
color: white;
}
.dRPLB {
background: #EEEEEE;
}
.dRPPopup {
width: 8em;
height: 2em;
}
.mycal .datePickerPreviousButton { visibility: visible; color: gray; }
.mycal .datePickerNextButton { visibility: visible; color: gray; }
.mycal .datePickerWeekdayLabel{background: white;}
.mycal .datePickerMonthSelector { background: white; }
.mycal .datePickerMonth { background: white;color: orange;}
.mycal .datePickerWeekendLabel{background: white;}
.mycal .datePickerDayIsValue { background: orange;}
.mycal .datePickerDayIsWeekend { background: #D9D9D9;}
然后一切都完美适用
我将它作为一个独立的自定义小部件,为此我创建了一个单独的 css 文件。为了访问它,我创建了一个资源接口,如下所示,
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.resources.client.ImageResource;
public interface DateRangeTypePickerResources extends ClientBundle {
DateRangeTypePickerResources INSTANCE = GWT
.create(DateRangeTypePickerResources.class);
/*
* @Source("DocumentImg.jpg") ImageResource getDocumentImg();
*/
@Source("down.png")
ImageResource getDownImg();
@Source("up.png")
ImageResource getUpImg();
public interface DateRangeTypePickerCssStyle extends CssResource {
String dRPLable();
String dRPBtn();
String dRPLB();
String mycal();
String dRPPopup();
String datePickerPreviousButton();
String datePickerNextButton();
String datePickerWeekdayLabel();
String datePickerWeekendLabel();
String datePickerMonthSelector();
String datePickerMonth();
String datePickerDayIsValue();
String datePickerDayIsWeekend();
}
@Source("../widget/DateRangeTypePicker.css")
DateRangeTypePickerCssStyle DateRangeTypePickerCss();
}
我如何访问这些方法如下
public class DateRangePicker extends Composite {
static DateRangeTypePickerResources resources = GWT
.create(DateRangeTypePickerResources.class);
DateRangeTypePickerCssStyle css = DateRangeTypePickerResources.INSTANCE
.DateRangeTypePickerCss();
static {
DateRangeTypePickerResources.INSTANCE.DateRangeTypePickerCss()
.ensureInjected();
}
public DateRangePicker(DateRangePickerModel dateRangePickerModel) {
Label startDateLabel = new Label("Start Date");
startDtToday.setStylePrimaryName(css.dRPLabel());
flexTable.setWidget(0, 0, startDateLabel);
DatePicker startDatePicker = new DatePicker();
startDatePicker.setStyleName(css.mycal());
}
}
这里的样式正在申请标签。但是 Style 并没有申请 DatePicker。如何从 CssResources 类将自定义样式应用于 DatePicker?