CompactCalendarView
CompactCalendarView copied to clipboard
Can i change the text color just for the weekend (Saturday and Sunday)
Hi, @SundeepK this calendar is Great, but i still need some customize here. i need set the weekend text color become red color.
or how to intercept the Binding process for each date?
Thanks,
Unfortunately, there is no way built in todo this at the moment. This can be done pretty easily I think. I don't know when I will get around this since there are other issues that need to be addressed. But if you want to hack it todo it quickly, take a fork of the code, you simply need to check if the date is a weekend and color it different.
In this line: https://github.com/SundeepK/CompactCalendarView/blob/master/library/src/main/java/com/github/sundeepk/compactcalendarview/CompactCalendarController.java#L870
You need Something like this (might need to adjust it as its off top of my head):
if (day == 7 || day == 1) {
dayPaint.setStyle(Paint.Style.FILL);
dayPaint.setColor(calenderTextColor);
} else {
dayPaint.setStyle(Paint.Style.FILL);
dayPaint.setColor(Color.CYAN);
}
canvas.drawText(String.valueOf(day), xPosition, yPosition, dayPaint);
Hope that makes sense.
Hi @SundeepK, this task is very relevant to my app as well It would be great if I could customize the calendar this way.
Hi @SundeepK, I need this as well, I have 2 events with the outside ring showing as colors, and no matter which way I enter the events in the color stays the same, I want to be able to change the color manually.
Hi @hualoqueros @SundeepK @lucasrafagnin @Edonfreiner
Use below code to change weekend colors ,
void drawMonth(Canvas canvas, Calendar monthToDrawCalender, int offset) {
HashSet<Integer> integers= getWeekEndsFormMonthYear();
//Change weekend days name
if(dayColumn==5||dayColumn==6)
{
dayPaint.setColor(Color.BLACK);
}
//Change weekend days
dayPaint.setStyle(Paint.Style.FILL);
dayPaint.setColor(defaultCalenderTextColorToUse);
for(Integer integer:integers)
{
if (day==integer) {
dayPaint.setStyle(Paint.Style.FILL);
dayPaint.setColor(Color.BLACK);
}
}
}
Calendar getCalendarOfCurrentMonth() {
Calendar calendar = Calendar.getInstance(timeZone, locale);
calendar.setTime(currentDate);
calendar.add(Calendar.MONTH, -monthsScrolledSoFar);
calendar.set(Calendar.DAY_OF_MONTH, 1);
setToMidnight(calendar);
return calendar;
}
// https://stackoverflow.com/a/3272519/1573336
private HashSet<Integer> getWeekEndsFormMonthYear()
{
HashSet<Integer> hs = new HashSet<>();
Calendar cal = getCalendarOfCurrentMonth();
int month = cal.get(Calendar.MONTH);
do {
// get the day of the week for the current day
int day = cal.get(Calendar.DAY_OF_WEEK);
// check if it is a Saturday or Sunday
if (day == Calendar.SATURDAY || day == Calendar.SUNDAY) {
hs.add(cal.get(Calendar.DAY_OF_MONTH));
// print the day - but you could add them to a list or whatever
System.out.println(cal.get(Calendar.DAY_OF_MONTH));
}
// advance to the next day
cal.add(Calendar.DAY_OF_YEAR, 1);
} while (cal.get(Calendar.MONTH) == month);
return hs;
}
Hello, Friends how i to show 12 months in one activity..is it possible