Android 将事件添加到 CalendarView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22000585/
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-08-20 05:24:55  来源:igfitidea点击:

Add event to CalendarView

androidandroid-calendarcalendarview

提问by Cilenco

I think the question says it all: is it possible to display events in the Android default CalendarView?

我认为这个问题说明了一切:是否可以在 Android 默认中显示事件CalendarView

I know that it is made for widgets and not for a real Calendar application but my app should not be a Calendar application. It is only a little feature in my app so I think the View is perfect for my claims. I only can't view events in it, otherwise it is perfect for me.

我知道它是为小部件而不是真正的日历应用程序制作的,但我的应用程序不应该是日历应用程序。它只是我应用程序中的一个小功能,所以我认为 View 非常适合我的主张。我只是无法查看其中的事件,否则它对我来说是完美的。

I read this answerand tried to overwrite the onDraw method from CalenderView:

我阅读了这个答案,并试图从CalenderView以下位置覆盖 onDraw 方法:

@Override
protected void onDraw(Canvas canvas)
{
    p = new Paint();

    p.setColor(Color.RED);
    p.setStrokeWidth(10);

    super.onDraw(canvas);
    canvas.drawRect(0, 0, 100, 100, p);
}

But even this code does not work and no rectangle is displayed. The other 4 methods are privateso I can't overwrite them. Any other ideas how I can solve this problem? I do not want to use a library, but if there is no other way I'm looking for something what is really near to the stock CalendarView. Or maybe I can create a calendar file which is only visible in my app and not in other calendar apps?

但即使这段代码也不起作用,也没有显示矩形。其他 4 种方法是private这样我不能覆盖它们。我还有其他想法可以解决这个问题吗?我不想使用图书馆,但如果没有其他方法,我正在寻找真正接近库存的东西CalendarView。或者我可以创建一个仅在我的应用程序中可见而在其他日历应用程序中不可见的日历文件?

回答by Mehul Joisar

You can't add events in default CalendarView. either you need to make it custom or you need to use some library.

您不能在 default 中添加事件CalendarView。要么你需要定制它,要么你需要使用一些库。

I have used Caldroidlibrary many times.it is easy to implement and robust.

我已经多次使用Caldroid库。它易于实现且健壮。

enter image description here

在此处输入图片说明

回答by Sun

Shameless plug. I've also written my own android CalendarView which allows you to add events, listeners, provides infinite scrolling and is a gradle project: https://github.com/SundeepK/CompactCalendarView.

无耻的插头。我还编写了自己的 android CalendarView,它允许您添加事件、侦听器、提供无限滚动,并且是一个 gradle 项目:https: //github.com/SundeepK/CompactCalendarView