Android日历标题在物料日历视图中显示错误的月份和年份
我正在使用库显示特定月份。我使用了Android日历标题在物料日历视图中显示错误的月份和年份,android,android-calendar,calendarview,Android,Android Calendar,Calendarview,我正在使用库显示特定月份。我使用了setMinimumDate()和setMaximumDate()来获得这个功能 我的XML代码是: <com.prolificinteractive.materialcalendarview.MaterialCalendarView xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/calendarView" android:layout_wi
setMinimumDate()
和setMaximumDate()
来获得这个功能
我的XML代码是:
<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="none"
app:mcv_calendarMode="month"
app:mcv_firstDayOfWeek="saturday"/>
此处日历应显示2016年2月。它正确显示日期信息,但日历标题始终显示当前月份和年份(添加图像)
如何解决此问题?……在这些文档中,他们说他们不保证修改将保留。。。在标题重大变化1.4.0下经过长时间的研究,我从他们的标题中(在标题部分)得到了一个解决方案 下面给出了我的
onCreateView()
方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_calendar_view, container, false);
materialCalendarView = (MaterialCalendarView) view.findViewById(R.id.calendarView);
final Calendar firstDate=Calendar.getInstance();
firstDate.set(2016, 1, 1, 0, 0, 0); // 1st February, 2016
Calendar lastDate=Calendar.getInstance();
lastDate.set(2016, 1, 29, 0, 0, 0); // 29th February, 2016
materialCalendarView.state().edit()
.setMinimumDate(firstDate) // 1st February, 2016
.setMaximumDate(lastDate) // 29th February, 2016
.commit();
materialCalendarView.setTitleFormatter(new TitleFormatter() {
@Override
public CharSequence format(CalendarDay day) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMMM yyyy", Locale.US); //"February 2016" format
String monthAndYear = simpleDateFormat.format(firstDate.getTime());
return monthAndYear;
}
});
materialCalendarView.setOnDateChangedListener(this);
materialCalendarView.setOnMonthChangedListener(this);
return view;
}
我不确定这是不是最好的做法,但它解决了我的问题。如果有其他解决这个问题的好方法,请给出您的解决方案。是吗?我现在该怎么办?在文件中他们说他们不保证修改会保留。。。请在“主要变更1.4.0”下发布文档链接,以供OP参考?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_calendar_view, container, false);
materialCalendarView = (MaterialCalendarView) view.findViewById(R.id.calendarView);
final Calendar firstDate=Calendar.getInstance();
firstDate.set(2016, 1, 1, 0, 0, 0); // 1st February, 2016
Calendar lastDate=Calendar.getInstance();
lastDate.set(2016, 1, 29, 0, 0, 0); // 29th February, 2016
materialCalendarView.state().edit()
.setMinimumDate(firstDate) // 1st February, 2016
.setMaximumDate(lastDate) // 29th February, 2016
.commit();
materialCalendarView.setTitleFormatter(new TitleFormatter() {
@Override
public CharSequence format(CalendarDay day) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMMM yyyy", Locale.US); //"February 2016" format
String monthAndYear = simpleDateFormat.format(firstDate.getTime());
return monthAndYear;
}
});
materialCalendarView.setOnDateChangedListener(this);
materialCalendarView.setOnMonthChangedListener(this);
return view;
}