Android日历查看日期选取器

问题描述:

我正在写我的第一个应用程序,并且我有一个关于DatePicker的问题。Android日历查看日期选取器

我的应用需要用户输入日期。最人性化的方式将弹出窗口,显示当前月份像日历网格日历般的小部件 - 是这样的:

enter image description here

我想使用替代DatePicker接口 - 其中有月份,日期和年份字段,每个字段都有一个向上和向下按钮来增加/减少。

这种类型的功能内置于任何Android小部件或视图中,还是必须设计自己的自定义组件来执行此操作?我想这已经存在了,看看这种类型的UI在非移动应用程序和网页中经常使用多少。

谢谢!

+0

您能否将此任务所选答案更新至此任务离子?如果他们没有看到所有的答案,人们可​​能会误导他人。正如其他人的回应所述,API级别11+中有一个CalendarView。谢谢! – vosmith 2014-02-26 13:31:30

这种类型的功能是否内置到任何android小部件或视图中,还是必须设计我自己的自定义>组件来执行此操作?

在Android SDK中没有组件,对不起。您说明的小部件对触摸屏来说太小了。您可以实现更大的功能(请参阅日历应用程序),但您主要依靠自己的功能。

+1

你能指出我的日历应用程序代码吗? – 2012-02-16 18:05:11

+8

你可以提供日历应用程序的链接,你在你的答案中提到.. – Nishant 2012-04-25 09:52:12

我最近刚刚写了一个模块化的应用程序。这里有一些sample code,documentationscreenshots.apk download

+0

你能告诉我如何实现日历插件吗?没有关于如何安装它的信息 – 2012-02-16 18:06:53

+0

如何正确调整这些日历的大小? – superuser 2013-09-03 12:51:20

发现在http://caughtinthemobileweb.wordpress.com/2011/06/20/how-to-implement-calendarview-in-android/


良好的implemetation此外,由于API级别11(安卓3.0)有一直是C的本地实现alendarView http://developer.android.com/reference/android/widget/CalendarView.html

+0

+1提到本地日期选择器。还有DatePickerDialog:http://developer.android.com/reference/android/app/DatePickerDialog.html – 2012-06-20 23:22:04

+0

这里是伟大的重写没有网格视图︰https://github.com/AtRow/CalendarView – Cfr 2013-03-05 11:42:06

由于API 11本身有:CalendarView

enter image description here

这个观点是在HoloEverywhere因为API 7.

现在,在2014年,即使是本地DatePicker (link)含有少量全息寻找CalendarView (link)每月选择一天。

,您可以选择,如果两个纺纱和CalendarView或只是其中之一是通过设置显示:

  • android:calendarViewShown
  • android:spinnersShown

我不知道,如果它只是API级别16+或者甚至是冰淇淋三明治,但它在那里。这是它的外观默认:

enter image description here


此外,在API级别21和更高的有新材料主题DatePicker,看起来像以下:

enter image description here

这是API 21+上的默认设置,并且不再有旋钮,但可以通过设置

android:datePickerMode="spinner" 

在您的XML中。如果你想使用它像弹出写上你的onclick https://github.com/truefedex/android-date-picker enter image description here

+1

试过了有趣的ICS,看起来像holo – Zharf 2014-08-12 12:47:40

+0

@anoniim,谢谢datePickerMode提示! – user3855005 2015-02-23 09:01:20

尝试使用这个组件

if (calendarPopup == null) { 
    calendarPopup = new PopupWindow(getContext()); 
    CalendarPickerView calendarView = new CalendarPickerView(getContext()); 
    CalendarNumbersView calendar = (CalendarNumbersView) calendarView.findViewById(com.phlox.datepick.R.id.calendar); 
    calendar.setShowDayNames(false); 
    calendarView.setListener(onDateSelectionListener); 
    calendarPopup.setContentView(calendarView); 
    calendarPopup.setWindowLayoutMode(
     MeasureSpec.makeMeasureSpec(llCalendar.getWidth(), MeasureSpec.EXACTLY), 
     ViewGroup.LayoutParams.WRAP_CONTENT); 
    calendarPopup.setHeight(1); 
    calendarPopup.setWidth(llCalendar.getWidth()); 
    calendarPopup.setOutsideTouchable(true); 
} 
calendarPopup.showAsDropDown(llCalendar); 

您可以使用此lib中日期选择

https://github.com/square/android-times-square/