12

I've got the calendarview in eclipse and now I'm trying to change the appearance of a single day to highlight dates. I didn't find any useful method here, only changes of appearances of whole weekdates or monthdates. So is there a possibility to highlight a single day?

Also i know there are like 3 posts with the same issue, but none of them got answered.

Werdli
  • 235
  • 1
  • 4
  • 11

2 Answers2

9

You could extend the native CalenderView to create your own CustomCalendarView and make any desired changes in appearance.

You can find the code for the native CalendarView here.

Abhishek Sabbarwal
  • 3,758
  • 1
  • 26
  • 41
  • 7
    Thanks, didn't know the native CalendarView. Still android should maybe implement a method for changing single day colors in CalendarView! – Werdli Apr 08 '13 at 09:14
  • I find the calendar view very confusing to use. I don't understand why the user wants to scroll vertically or horizontally as if you are reading a foot-long text document. I find this not ergonomic at all. I am looking for ways on how to prevent calendar from being scrolled and to show only one month per view. – Neon Warge Apr 09 '15 at 14:16
  • 3
    The CalendarView source link is dead. – Colin Basnett Aug 20 '15 at 22:57
  • Actual source code is here https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/CalendarView.java – artaxerx Jan 13 '22 at 07:08
4

You may do it by obtain the child views of the CalendarView and change there configuations:

    final CalendarView calendar = new CalendarView(this);       
    java.lang.reflect.Field field = null;

    Class<?> cvClass = calendar.getClass();
    try {
        field = cvClass.getDeclaredField("mDayNamesHeader");    
        field.setAccessible(true);
    } catch (NoSuchFieldException e) {
    }

    ViewGroup tv = null;
    try {
        tv = (ViewGroup) field.get(calendar);
    } catch (IllegalAccessException e) {} 
      catch (IllegalArgumentException ){}

    TextView k =  (TextView) tv.getChildAt(1);
    k.setTextColor(Color.RED);

Here You can find all declarations:

https://android.googlesource.com/platform/frameworks/base/+/2888524e03896831f487e5dee63f18f1c33c0115/core/java/android/widget/CalendarView.java

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
Stav Bodik
  • 2,018
  • 3
  • 18
  • 25