Android 安卓日历视图

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

Android calendar view

androidcalendarview

提问by Brian

I'm pretty new to Android development and I'm looking for a means of including calendar in my Android application, but I'm striking out pretty bad when googling.

我对 Android 开发还很陌生,我正在寻找一种在我的 Android 应用程序中包含日历的方法,但是我在谷歌搜索时表现得非常糟糕。

  1. Is there any way to use a default calendar kind of view in my application? (would be ideal since the UI would be familiar)

  2. Failing at a built-in option, are there any good libraries out there with a calendar control that I could use?

  1. 有什么方法可以在我的应用程序中使用默认日历类型的视图吗?(这将是理想的,因为用户界面会很熟悉)

  2. 内置选项失败了,有没有我可以使用的带有日历控件的好的库?

I'm not looking to sync and all of that (at least, at this point), just looking to have a calendar view that I can display information to the user.

我不希望同步和所有这些(至少在这一点上),只是希望有一个可以向用户显示信息的日历视图。

回答by thomasdao

I wrote Caldroid library (https://github.com/roomorama/Caldroid) that is simple to setup and have many features such as setup min/max date, disabled dates, select date range, swipe to change month, fully localized, support rotation properly etc. It's easy to customize the look and feel. Just to share if someone might find it useful :)

我编写了 Caldroid 库 ( https://github.com/roomorama/Caldroid),它易于设置并具有许多功能,例如设置最小/最大日期、禁用日期、选择日期范围、滑动更改月份、完全本地化、支持正确旋转等。很容易自定义外观和感觉。只是分享如果有人可能会觉得它有用:)

回答by OneWorld

I tried android-CalendarView, Caldroid and later switched to android-times-squarewhich has this improvements:

我尝试了android-CalendarView、 Caldroid ,后来切换到android-times-square,它有以下改进:

  • Much faster switching to other months due to vertical scrolling (no pagination which responds slow in Caldroid)
  • Indicators, highlighted dates (at least in this forkfor android)
  • iOS version available with the same look and feel
  • looks cleaner than the android version because months are clearly separated

    enter image description here

  • 由于垂直滚动而更快地切换到其他月份(没有分页,在 Caldroid 中响应缓慢)
  • 指标,突出显示的日期(至少在这个 forkfor android 中)
  • 具有相同外观和感觉的 iOS 版本可用
  • 看起来比 android 版本更干净,因为月份明显分开

    在此处输入图片说明

Just like Caldroid it is a part of a productive app.

就像 Caldroid 它是高效应用程序的一部分。

回答by Cristian

AFAIK, there are no other way than implement your own calendar. So... what you would have to do is using a GridLayoutwith 7 columns and create a custom BaseAdapterto display data correctly.

AFAIK,除了实现自己的日历之外别无他法。所以...您需要做的是使用GridLayout7 列并创建自定义BaseAdapter以正确显示数据。

回答by Simon Si

Android now provides three ways to incorporate calendars in your app.

Android 现在提供了三种将日历合并到您的应用程序中的方法。

  1. Calendar viewfor picking dates and such.

  2. Calendar providercan be accessed to add and remove events from the OS calendar.

  3. Calendar intentsallow you to provide a calendar without having to get extra permissions or deal with databases.

  1. 用于选择日期等的日历视图

  2. 可以访问日历提供程序以在操作系统日历中添加和删除事件。

  3. 日历意图允许您提供日历而无需获得额外的权限或处理数据库。

回答by Philippe

This library seems really nice and with a more modern UI (Material Design) :

这个库看起来非常好,并且具有更现代的 UI(材料设计):

https://github.com/prolificinteractive/material-calendarview

https://github.com/prolificinteractive/material-calendarview

You just have to import it with gradle:

你只需要用 gradle 导入它:

compile 'com.prolificinteractive:material-calendarview:1.4.0'

And add it in your layout:

并将其添加到您的布局中:

<com.prolificinteractive.materialcalendarview.MaterialCalendarView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mcv_showOtherDates="all"
app:mcv_selectionColor="#00F"
/>

enter image description here

在此处输入图片说明

回答by John

it is possible but not easy. http://jimblackler.net/blog/?p=151&cpage=2#comment-52767

这是可能的,但并不容易。 http://jimblackler.net/blog/?p=151&cpage=2#comment-52767

and

private void InsertAppointment(String strTitle, String strDescription, String strEventLocation, long StartDateTime, long EndDateTime, boolean bAllDay, boolean bHasAlarm){
    int tAllday;
    int tHasAlarm;
    if (bAllDay = true){
        tAllday = 1;
    }
    else
        tAllday = 0;
    if (bHasAlarm = true){
        tHasAlarm = 1;
    }
    else
        tHasAlarm = 0;

    ContentValues event = new ContentValues();
    // Calendar in which you want to add Evenet
    event.put("calendar_id", CalId);                //CalId                                  
    event.put("title", strTitle);                                                           
    event.put("description", strDescription);                                  
    event.put("eventLocation", strEventLocation);                                                   
    event.put("dtstart", StartDateTime);                                                          
    event.put("dtend", EndDateTime );                  
    event.put("allDay", 0);                     
    event.put("hasAlarm", 0);                                                                  
    Uri eventsUri = Uri.parse("content://com.android.calendar/events");    
    // event is added
    getContentResolver().insert(eventsUri, event);

}

a quick search on content://com.android.calendar/calendarswill help get you started. but I'm not finished mine yet I just can't get the data out yet. but it is possible

快速搜索 content://com.android.calendar/calendars将帮助您入门。但我还没有完成我的,我只是无法得到数据。但这是可能的

回答by Santiago Carrillo

You can use the android calendar picker I have created, it is open source project and you can easily add it to your project.

您可以使用我创建的 android 日历选择器,它是开源项目,您可以轻松地将其添加到您的项目中。

https://github.com/sancarbar/Android-Calendar-Picker

https://github.com/sancarbar/Android-Calendar-Picker

回答by Mustafa Ferhan

You can use MFCalendarView: https://github.com/MustafaFerhan/MFCalendarView

您可以使用 MFCalendarView:https: //github.com/MustafaFerhan/MFCalendarView

set multiple events;

设置多个事件;

ArrayList<String> eventDays = new ArrayList<String>();
eventDays.add("2014-02-25");
eventDays.add(Util.getCurrentDate());

mf.setEvents(eventDays);

and handle with MFCalendarView's listener:

并处理 MFCalendarView 的侦听器:

mf = (MFCalendarView) findViewById(R.id.mFCalendarView);
mf.setOnCalendarViewListener(new onMFCalendarViewListener() {

    @Override
        public void onDisplayedMonthChanged(int month, int year, String monthStr) {
            }

            @Override
            public void onDateChanged(String date) {
            }
    });

It's very simple.

这很简单。