Can I apply background image instead of background color for Calendar cell?

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

    Posted 09 Jun 2015 Link to this post

    I want to apply background image because I have one scenario like on 2nd June employee half day on on-duty(outside for office work) and half day in office or absent.

    CASE:1

    I want to add background color for this scenario half cell is Green and half cell is Blue is this possible ?

    CASE:2

    I want to add background image for this scenario is this possible?

    Please let me know the correct solution.

    Thanks

     

  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 12 Jun 2015 Link to this post

    Hi Vijay,

    Thanks for writing.

    You can add an image to the CalendarCell as part of the CustomizationRule mechanism. We are using it one of our examples that are available in the store, here is the full code, and here's just an excerpt with the customization part which does that:

    this.calendarView.setCustomizationRule(new Procedure<CalendarCell>() {
        @Override
        public void apply(CalendarCell argument) {
            if (argument.getCellType() == CalendarCellType.Date) {
                calendar.setTimeInMillis(argument.getDate());
                if (calendar.get(Calendar.DAY_OF_MONTH) == 6 || calendar.get(Calendar.DAY_OF_MONTH) == 7) {
                    argument.setBackgroundColor(Color.parseColor("#f9cc9d"), Color.parseColor("#f9cc9d"));
                    argument.setBorderColor(borderColor);
                    argument.setBorderWidth(borderWidth);
                    argument.setBitmap(sun);
                } else {
                    argument.setBackgroundColor(colorEnabled, colorDisabled);
                    argument.setBorderColor(Color.TRANSPARENT);
                    argument.setBitmap(null);
                }
            }
        }
    });

    This changes the background color, the border color, the border width and adds an image for dates that are 6th or 7th. You can use this approach to add image to dates of your choice. The half-coloring of dates is not supported, but you may be able to achieve a similar result by setting for example Green background for the cell and adding a simple Blue image.

    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
  3. DevCraft banner
  4. Jaune
    Jaune avatar
    1 posts
    Member since:
    Feb 2016

    Posted 26 Feb Link to this post

    Hi,

    I am using Xamarin for Android. How can I implement setBitmap for a CalendarCell in C#?

     

  5. Todor
    Admin
    Todor avatar
    778 posts

    Posted 02 Mar Link to this post

    Hello Jaune,

    Yes, in Xamarin for Android the approach is quite similar. Here's the article which contains a C# snippet for the customization rule. The difference is that in java the bitmap is set through the setBitmap method, while in C# it is done through the Bitmap property:

    argument.Bitmap = sun;

    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