CalendarView minimum date

2019-01-29 08:08发布

问题:

I created a CalendarView and I don't want to show previous months.

I tried this:

Calendar calendar = Calendar.getInstance();
int date = calendar.getActualMinimum(Calendar.DATE);

CalendarView calendar_view = (CalendarView) findViewById(R.id.calendar);
calendar_view.setMinDate(date);

Nothing seems to happen. The calendar works as normal.

回答1:

Try calculating the date like this:

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DATE,Calendar.getInstance().getActualMinimum(Calendar.DATE));
long date = calendar.getTime().getTime();

and set this as minimum date:

calendar_view.setMinDate(date);

since calendar_view.setMinDate(date) needs long value that represents milliseconds.



回答2:

You can just set the min date as below.

 Calendar c = Calendar.getInstance();
 CalendarView cv = (CalendarView)findViewById(R.id.calendarView);
 cv.setMinDate(c.getTimeInMillis());