rainer
rainer

Reputation: 3411

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.

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.

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);

}

Upvotes: 1

Views: 146

Answers (2)

rainer
rainer

Reputation: 3411

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:

mycalender-day {

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

Upvotes: 0

Shai Almog
Shai Almog

Reputation: 52760

I'm assuming you are using the com.codename1.ui.Calendar class. 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.

Upvotes: 0

Related Questions