【问题标题】:Changing color of single day in calendarview, android在日历视图中更改单日的颜色,android
【发布时间】:2013-04-08 08:06:55
【问题描述】:

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

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

【问题讨论】:

标签: java android eclipse calendarview


【解决方案1】:

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

您可以找到原生 CalendarView 的代码here

【讨论】:

  • 谢谢,不知道原生 CalendarView。仍然 android 可能应该实现一个在 CalendarView 中更改单日颜色的方法!
  • 我发现日历视图使用起来非常混乱。我不明白为什么用户要垂直或水平滚动,就好像您正在阅读一英尺长的文本文档一样。我发现这根本不符合人体工程学。我正在寻找如何防止日历被滚动并且每次视图只显示一个月的方法。
  • CalendarView 源链接已失效。
【解决方案2】:

您可以通过获取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);

在这里你可以找到所有的声明:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多