How do I change the text color of an event?

3 posts, 1 answers
  1. Craig
    Craig avatar
    2 posts
    Member since:
    Jun 2015

    Posted 16 Jun 2015 Link to this post

    I'm evaluating the xamarin version of the telerik calendar and I've been struggling with styling events. There seem to be examples of how to change the shape of an event, but when I implement those examples, the text of the event goes away. There also does not seem to be any way to globally set this for all events. so here's what I'm doing so far:

    RadCalendarView calendarView = FindViewById<RadCalendarView>(Resource.Id.calendarView);

    calendarView.Adapter.Style = Com.Telerik.Widget.Calendar.CalendarStyles.MaterialDark(this);                

    which sets the style mostly how I want, but the text is black of the events and I want it to be white. so I overrode the EventRenderer and that's when the text goes away.

            public class MyEventRenderer : EventRenderer
            {
                private Paint paint;

                public MyEventRenderer(Context context)
                    : base(context)
                {
                    paint = new Paint();
                    paint.AntiAlias = true;
                }

                public override void RenderEvents(Android.Graphics.Canvas canvas, CalendarDayCell cell)
                {
                    int desiredOffset = 20;
                    int shapeRadius = 10;
                    int locationX = cell.Left + 20;
                    int locationY = cell.Top + 50;

                    cell.TextColor = Android.Graphics.Color.ParseColor("#FFFFFF");

                    foreach (Event e in cell.Events)
                    {
                        this.paint.Color = new Android.Graphics.Color(e.EventColor);
                        canvas.DrawCircle(locationX, locationY, shapeRadius, this.paint);
                        locationY += shapeRadius + desiredOffset;
                    }
                }
            }

    Please let me know what I'm missing. thanks, Craig

  2. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 19 Jun 2015 Link to this post

    Hi Craig,

    Thank you for your interest in RadCalendarView.

    The EventRenderer is responsible for all the information about the events that will be drawn including the text. Since in your method you only draw a circle it is expected that there is no text. Here's an example where you draw not only a circle but also text for each event:

    foreach (Event e in cell.Events)
    {
        this.paint.Color = new Android.Graphics.Color(e.EventColor);
        canvas.DrawCircle(locationX, locationY, shapeRadius, this.paint);
        locationY += shapeRadius + desiredOffset;
        canvas.DrawText (e.Title, textLocationX, textLocationY, paint);
    }

    Of course, you can use text locations and paint of your choice, which don't need to be the same for the text and the circle.

    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. Craig
    Craig avatar
    2 posts
    Member since:
    Jun 2015

    Posted 19 Jun 2015 in reply to Todor Link to this post

    Exactly what I needed! That worked perfectly. thanks.
Back to Top