Android-Week-View
Android-Week-View copied to clipboard
How can I just add borders instead of background color for the event?
I am new to android and using this calendar for my project. I need to show borders instead of background color. Need help! Thanks
You can use different colors for each event.
mWeekView.setMonthChangeListener((newYear, newMonth) ->
{
List<WeekViewEvent> events = new ArrayList<>();
for (int i = 0; i < calendarEvents.size(); i++) {
CalendarEvent calendarEvent = calendarEvents.get(i);
Calendar startDate = Calendar.getInstance();
startDate.setTime(calendarEvent.startDate);
Calendar endDate = Calendar.getInstance();
endDate.setTime(calendarEvent.endDate);
if (startDate.get(Calendar.MONTH) + 1 == newMonth &&
endDate.get(Calendar.MONTH) + 1 == newMonth &&
startDate.get(Calendar.YEAR) == newYear &&
endDate.get(Calendar.YEAR) == newYear) {
WeekViewEvent weekViewEvent = new WeekViewEvent(2, calendarEvent.eventName + "\n" + calendarEvent.typeName, startDate, endDate);
if (calendarEvent.typeName.equals("EventType1"))
weekViewEvent.setColor(getResources().getColor(R.color.event_color_01));
if (calendarEvent.typeName.equals("EventType2"))
weekViewEvent.setColor(getResources().getColor(R.color.event_color_02));
if (calendarEvent.typeName.equals("EventType3"))
weekViewEvent.setColor(getResources().getColor(R.color.event_color_03));
if (calendarEvent.typeName.equals("EventType4"))
weekViewEvent.setColor(getResources().getColor(R.color.event_color_04));
if (calendarEvent.typeName.equals("EventType5"))
weekViewEvent.setColor(getResources().getColor(R.color.event_color_05));
weekViewEvent.setId(calendarEvent.eventId);
events.add(weekViewEvent);
}
}
return events;
}
@arshad104 you can adopt the library instead of compiling it..In the weekView class there is a method "drawEvents". If you browse throught the method you can see the canvas being drawn for the event in the line canvas.drawRect(params). Currently this function draws a rectangle with the color specified in the last parameter. You can modify the code as
canvas.drawLine(left,top,right,top,COLOR); canvas.drawLine(left,bottom,right,bottom,COLOR); canvas.drawLine(left,top,left,top,COLOR); canvas.drawLine(right,top,right,bottom,COLOR); canvas.drawRect(left,top,right,bottom,Color.WHITE);
This would draw a white or preferred color rectangle and also add lines to the border of the rectangle. Hope this helps
It would be great if this could be included as a modifiable parameter in the XML.
Another interesting work around is to simply subtract 1 minute from the end of every event.