我正在使用android材质日历,正在制作怀孕日历,因为如果我接下来几天要单击“一日选择”,则在其中自动添加图标,这是我的代码:
calendarView.setOnDayClickListener(new OnDayClickListener() {
@Override
public void onDayClick(EventDay eventDay) {
Calendar clickedDayCalendar = eventDay.getCalendar();
/* clickedDayCalendar.set( clickedDayCalendar.get(Calendar.DAY_OF_MONTH + 4) , clickedDayCalendar.get(Calendar.MONTH) , clickedDayCalendar.get(Calendar.YEAR));*/
events.add(new EventDay(clickedDayCalendar, R.drawable.sample_icon_2));
ArrayList<String> eventDays = new ArrayList<String>();
calendarView.setEvents(events);
/* alert_diaog_picker(eventDay.getCalendar().getTime().toString());*/
// Calendar clickedDayCalendar = eventDay.getCalendar();
/* Toast.makeText(getContext(), "Selected Date:\n" + "Day = " + clickedDayCalendar.get(Calendar.DAY_OF_MONTH) +
"\n" + "Month = " + clickedDayCalendar.get(Calendar.MONTH) + "\n" + "Year = " + clickedDayCalendar.get(Calendar.YEAR), Toast.LENGTH_LONG).show();*/
}
});
return view;
}
这是我的xml代码:
<com.applandeo.materialcalendarview.CalendarView
android:id="@+id/calendarView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:abbreviationsBarColor="#303F9F"
app:abbreviationsLabelsColor="@android:color/white"
app:daysLabelsColor="@android:color/white"
app:headerColor="#1A237E"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:pagesColor="#3F51B5"
app:eventsEnabled="false"
app:selectionColor="@android:color/white"
app:selectionLabelColor="#3F51B5"
app:anotherMonthsDaysLabelsColor="#3F51B5"
app:todayLabelColor="#AEEA00"
app:type="many_days_picker" />
<Button
android:id="@+id/getDateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get date"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/calendarView" />
implementation 'com.applandeo:material-calendar-view:1.6.0'
现在它的工作方式就像当我单击该日期时仅包含该日期的图标,但我想在接下来的四天添加一个图标,请帮助我提前谢谢您,我感谢每个答案
答案 0 :(得分:0)
下面一行:
events.add(new EventDay(clickedDayCalendar, R.drawable.sample_icon_2));
尝试添加,
// To add an icon on another next four days
EventDay eventDay1=eventDay+1;
EventDay eventDay2=eventDay+2;
EventDay eventDay3=eventDay+3;
EventDay eventDay4=eventDay+4;
Calendar clickedDayCalendar1 = eventDay1.getCalendar();
events.add(new EventDay(clickedDayCalendar1,R.drawable.your_custom_icon));
Calendar clickedDayCalendar2 = eventDay2.getCalendar();
events.add(new EventDay(clickedDayCalendar2,R.drawable.your_custom_icon));
Calendar clickedDayCalendar3 = eventDay3.getCalendar();
events.add(new EventDay(clickedDayCalendar3,R.drawable.your_custom_icon));
Calendar clickedDayCalendar4 = eventDay4.getCalendar();
events.add(new EventDay(clickedDayCalendar4,R.drawable.your_custom_icon));