简体   繁体   English

在CodenameOne中设置日历单元格的背景颜色

[英]Set background colors of calendar cells in CodenameOne

I would like to change the background color for several days at once in a CodenameOne calendar. 我想在CodenameOne日历中一次更改几天的背景颜色。

Is this possible? 这可能吗? Does anyone maybe have a code example? 有人可能有代码示例吗?

I imagine obtaining dates from a list or a hash table (like: 01-08-2017, 05-08-2017, 20-08-2017) and set a distinct background color for these days in the calendar. 我想象从列表或哈希表(例如:01-08-2017、05-08-2017、20-08-2017)中获取日期,并为日历中的这些天设置不同的背景色。

Here is what I have so far: 这是我到目前为止的内容:

@Override
protected void updateButtonDayDate(Button dayButton, int currentMonth, int day) {

        //Customize day values

        dayButton.setText("" + day);

        Style s = dayButton.getAllStyles();

        s.setPaddingTop(3);
        s.setPaddingBottom(3);
        s.setBgColor(ColorUtil.BLUE);
        s.setBgTransparency(255);

        //s.setBorder(null);

}

I'm assuming you are using the com.codename1.ui.Calendar class. 我假设您正在使用com.codename1.ui.Calendar类。 The trick for customizing that is to derive the class and override the updateButtonDayDate method where you can set the UIID for the specific selected day to anything you want. 自定义的技巧是派生类并覆盖updateButtonDayDate方法,在该方法中,您可以将特定选定日期的UIID设置为所需的任何内容。

I found the following solution : 我发现以下解决方案:

To select or display multiple dates in a Codename Calendar, one option is adding the dates to a list and format the date buttons according to the list items : 要在代号日历中选择或显示多个日期,一种选择是将日期添加到列表中,并根据列表项设置日期按钮的格式:

 cal = new Calendar() {

        @Override
        protected void updateButtonDayDate(Button dayButton, int currentYear, int currentMonth, int day  ) {

            list.add(1);
            list.add(12);
            list.add(13);
            list.add(14);
            list.add(21);


            for (int day_Number : list) {

                if (day_Number == day) {

                    dayButton.setText("" + day);
                    dayButton.setUIID("mycalender-day");

                }

        }

    };

The css file contains the formatting style: css文件包含格式样式:

mycalender-day {

border: 1px solid whitesmoke;
color:orange;
font-family:  "native:MainRegular";
font-size: 7pt;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM