Android Calendar View for Date Picker

一笑奈何 提交于 2019-11-27 11:02:47

Is this type of functionality built into any android widget or view, or would I have to design my own custom > component to do this?

There is no component for that in the Android SDK, sorry. The widget you illustrate is too small for a touchscreen. You can implement something larger (see the Calendar app), but you are largely on your own for that.

Now, in 2014, even the native DatePicker (link) contains small Holo looking CalendarView (link) to pick a day in month.

You can choose, if both spinners and CalendarView or just one of them is displayed by setting:

  • android:calendarViewShown
  • android:spinnersShown

I'm not sure if it's just API level 16+ or if it was even in Ice Cream Sandwich, but it's there. This is how it looks by default:


Moreover, on API level 21 and higher there is a new Material themed DatePicker that looks like following:

This is default on API 21+ and there are no spinners anymore, but you can switch back to the Holo one by setting

android:datePickerMode="spinner"

in your XML.

Since the API 11 there natively: CalendarView

This View is in HoloEverywhere since API 7.

I have recently written exactly this as a modular app. Here is some sample code, documentation with screenshots, and .apk download.

Found a good implemetation in http://caughtinthemobileweb.wordpress.com/2011/06/20/how-to-implement-calendarview-in-android/


Also Since API level 11 (Android 3.0) there has been the native implementation of the CalendarView http://developer.android.com/reference/android/widget/CalendarView.html

Try to use this component: https://github.com/truefedex/android-date-picker

If you want to use it like popup write on your onclick:

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);

you can use this lib for date selection

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!