我在图书馆下方使用了日历,但是它显示的第一个星期几是星期一,我想从星期日开始。
https://github.com/Applandeo/Material-Calendar-View
我已经相应地更改了代码,但是它仍然显示相应的日期,星期一是第一天。
ArrayList<Date> days = new ArrayList<>();
// Get Calendar object instance
Calendar calendar = (Calendar) mCalendarProperties.getCurrentDate().clone();
// Add months to Calendar (a number of months depends on ViewPager position)
calendar.add(Calendar.MONTH, position);
// Set day of month as 1
calendar.set(Calendar.DAY_OF_MONTH, 1);
// Get a number of the first day of the week
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
// Count when month is beginning
int monthBeginningCell = dayOfWeek + (dayOfWeek == 1 ? 5 : -2);
// Subtract a number of beginning days, it will let to load a part of a previous month
calendar.add(Calendar.DAY_OF_MONTH, -monthBeginningCell);
/*
Get all days of one page (42 is a number of all possible cells in one page
(a part of previous month, current month and a part of next month))
*/
while (days.size() < 42) {
days.add(calendar.getTime());
calendar.add(Calendar.DAY_OF_MONTH, 1);
}
mPageMonth = calendar.get(Calendar.MONTH) - 1;
CalendarDayAdapter calendarDayAdapter = new CalendarDayAdapter(this, mContext,
mCalendarProperties, days, mPageMonth);
mCalendarGridView.setAdapter(calendarDayAdapter);
答案 0 :(得分:0)
尝试一下:
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);