gpt4 book ai didi

android - 如何在 Android Material Calendar 中禁用日期

转载 作者:行者123 更新时间:2023-11-29 17:18:34 25 4
gpt4 key购买 nike

我正在使用 Material CalendarView 和基于 array 的日期 CalenderView 突出显示日期。所以我想禁用除日期数组之外的日期。

 datePickerDialog = new Dialog(MainActivity.getInstance());
datePickerDialog.show();
datePickerDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
datePickerDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
datePickerDialog.setCancelable(true);
datePickerDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
datePickerDialog.setContentView(R.layout.assignment_custom_datepicker);
materialCalendarView = (MaterialCalendarView) datePickerDialog.findViewById(R.id.calendarView);
// materialCalendarView.setShowOtherDates(MaterialCalendarView.SHOW_ALL);
materialCalendarView.setFirstDayOfWeek(Calendar.SUNDAY);
materialCalendarView.invalidate();

materialCalendarView.setHeaderTextAppearance(R.style.TextAppearance_AppCompat_Medium);
materialCalendarView.setDateTextAppearance(R.drawable.background_solid_blue);
materialCalendarView.setDateTextAppearance(R.style.TextAppearance_AppCompat_Medium);
materialCalendarView.setWeekDayTextAppearance(R.style.TextAppearance_AppCompat_Medium);
materialCalendarView.setSelectionMode(MaterialCalendarView.SELECTION_MODE_SINGLE);

// materialCalendarView.setWeekDayTextAppearance();
materialCalendarView.setDateTextAppearance(R.style.WalletFragmentDefaultButtonTextAppearance);
Calendar selectDayCalendar = Calendar.getInstance();
selectDayCalendar.set(mYear, mMonth, mDay);
materialCalendarView.addDecorators(
new OneDayDecorator()
);
if (calendarDays != null && !calendarDays.isEmpty() ) {
materialCalendarView.addDecorator(new EventDecorator(Color.RED, calendarDays));
materialCalendarView.setOnDateChangedListener(this);


}
else
{
// materialCalendarView.setOnDateChangedListener(this);
}
if (readcalendarDays != null && !readcalendarDays.isEmpty()) {
materialCalendarView.addDecorator(new EventDecorator(Color.GREEN, readcalendarDays));

}

最佳答案

尝试以下操作:

ArrayList<CalendarDay> enabledDates = new ArrayList<>();

//Some for loop on dates{
enabledDates.add(new CalendarDay(date));
}

materialCalendarView.addDecorator(calendarDecorator.new DayEnableDecorator(enabledDates));

DayEnableDecorator 是一个单独的类:

public class DayEnableDecorator implements DayViewDecorator{
private HashSet<CalendarDay> dates;

public DayEnableDecorator(Collection<CalendarDay> dates) {
this.dates = new HashSet<>(dates);
}

@Override
public boolean shouldDecorate(CalendarDay day) {
return dates.contains(day);
}

@Override
public void decorate(DayViewFacade view) {
view.setDaysDisabled(false);
}
}

这将启用您放入数组 enabledDates 中的日期并禁用其余日期

关于android - 如何在 Android Material Calendar 中禁用日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37649567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com