eclipse 在日历视图中更改一天的颜色,android

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15874175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:20:52  来源:igfitidea点击:

Changing color of single day in calendarview, android

javaandroideclipsecalendarview

提问by Werdli

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?

我在 eclipse 中有日历视图,现在我试图改变一天的外观以突出显示日期。我在这里没有找到任何有用的方法,只有整个星期或月份的外观变化。那么是否有可能突出显示某一天?

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

我也知道有 3 个帖子有同样的问题,但没有一个得到回答。

采纳答案by Abhishek Sabbarwal

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

您可以扩展本机 CalenderView 以创建您自己的 CustomCalendarView 并在外观上进行任何所需的更改。

You can find the code for the native CalendarView here.

您可以在此处找到本机 CalendarView 的代码。

回答by Stav Bodik

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

您可以通过获取子视图CalendarView并更改那里的配置来实现:

    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://android.googlesource.com/platform/frameworks/base/+/2888524e03896831f487e5dee63f18f1c33c0115/core/java/android/widget/CalendarView.java