Changing color of single day in calendarview, android

a 夏天 提交于 2021-02-18 05:12:04

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/15874175/changing-color-of-single-day-in-calendarview-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!