This is a migrated thread and some comments may be shown as answers.

How to make every date in different different background color

3 Answers 944 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
vijay
Top achievements
Rank 1
vijay asked on 26 May 2015, 06:30 AM

Hi Antony, 

 

I want to add color coded functionality in my application because its based on Hr management application.

everything - general shift ,absent, present, holiday, leave (needs different background color)

weekends in different background  color ,week days in different different background color.

I tried this works but not succeed.

please help me out of this and provide me solution for this.

Thanks

3 Answers, 1 is accepted

Sort by
0
Antony Jekov
Telerik team
answered on 26 May 2015, 07:21 AM
Hi Kumar,

You will again need to use the customization rule. Something like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 
    RadCalendarView calendarView = new RadCalendarView(this);
    calendarView.setCustomizationRule(new Procedure<CalendarCell>() {
         
        Random random = new Random();
        int[] colors = {Color.RED, Color.BLUE, Color.CYAN, Color.GREEN, Color.MAGENTA};
         
        @Override
        public void apply(CalendarCell argument) {
            if (argument.getCellType() == CalendarCellType.Date) {
                int color = colors[random.nextInt(colors.length)];
                argument.setBackgroundColor(color, color);
            }
        }
    });
 
    setContentView(calendarView);
}

I hope this helps.

Regards,
Antony Jekov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
vijay
Top achievements
Rank 1
answered on 27 May 2015, 04:57 AM

Hi Antony,

This random dates color work, but i don't want to apply color on random dates.I want to apply color on some specific dates.Is there any solution for this kind of requirements.

Thanks

0
Todor
Telerik team
answered on 01 Jun 2015, 11:27 AM
Hello Vijay,

The random dates are just as an example. The same approach can be utilized for any dates, depending on your requirements. What's important is the main idea and that is the CustomizationRule conception. That is a procedure that is applied for each cell before it is drawn. For example you can store your shift (or whatever dates you need to customiza) in an array list (for example named myShifts) and if you want these dates to be colored in blue, you need to see first if the cell contains a date (by using getCellType) and if the date that it represents is the same as one of your dates and if so, set its color:

calendarView.setCustomizationRule(new Procedure<CalendarCell>() {
        @Override
        public void apply(CalendarCell argument) {
            if (argument.getCellType() == CalendarCellType.Date && myShifts.contains(argument.getDate()) {
                argument.setBackgroundColor(Color.BLUE, Color.BLUE);
            }
        }
    });

I hope this information helps.

Regards,
Todor
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Calendar
Asked by
vijay
Top achievements
Rank 1
Answers by
Antony Jekov
Telerik team
vijay
Top achievements
Rank 1
Todor
Telerik team
Share this question
or