How to make every date in different different background color

4 posts, 0 answers
  1. vijay
    vijay avatar
    23 posts
    Member since:
    May 2015

    Posted 26 May 2015 Link to this post

    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

  2. Antony Jekov
    Admin
    Antony Jekov avatar
    88 posts

    Posted 26 May 2015 Link to this post

    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
  3. DevCraft banner
  4. vijay
    vijay avatar
    23 posts
    Member since:
    May 2015

    Posted 26 May 2015 in reply to Antony Jekov Link to this post

    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

  5. Todor
    Admin
    Todor avatar
    778 posts

    Posted 01 Jun 2015 Link to this post

    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
Back to Top
DevCraft banner