gpt4 book ai didi

android - 在 Xamarin.Android 中使用 MaterialCalendarView 绑定(bind)库添加装饰

转载 作者:行者123 更新时间:2023-11-29 19:11:26 44 4
gpt4 key购买 nike

我正在使用 MaterialCalendarView我的 Xamarin.Android 应用程序中的库,除了我无法向日历添加跨度装饰外,它在大多数情况下都运行良好。

这是我的代码:

public class Calendar : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

SetContentView(Resource.Layout.Calendar);

MaterialCalendarView calendar = FindViewById<MaterialCalendarView>(Resource.Id.calendarView);
calendar.SetSelectedDate(Java.Util.Calendar.GetInstance(Java.Util.Locale.English));

List<CalendarDay> dates = new List<CalendarDay>();

CalendarDay a = CalendarDay.From(2017, 7, 10);
CalendarDay b = CalendarDay.From(2017, 7, 15);
CalendarDay c = CalendarDay.From(2017, 7, 9);
CalendarDay d = CalendarDay.From(2017, 6, 1);

dates.Add(a);
dates.Add(b);
dates.Add(c);
dates.Add(d);

//calendar.Post(() =>
//{
// calendar.AddDecorators(new EventDecorator(Android.Resource.Color.HoloOrangeLight, dates));
//});

calendar.AddDecorators(new EventDecorator(Android.Resource.Color.HoloOrangeLight, dates));

}
}

class EventDecorator : Java.Lang.Object, IDayViewDecorator
{
private int color;
private List<CalendarDay> dates;

public EventDecorator(int color, List<CalendarDay> dates)
{
this.color = color;
this.dates = dates;
}

public void Decorate(DayViewFacade view)
{
view.AddSpan(new DotSpan(5, color));
}

public bool ShouldDecorate(CalendarDay day)
{
//return dates.Contains(day);
return dates.Exists(e => (e == day));
}
}

如有任何帮助,我们将不胜感激!

最佳答案

I am unable add a span decoration to the calendar.

问题是当您使用 dates.Contains(day)dates.Exists(e => (e ==天))

它会比较HashCode firet所以它总是返回false,像下面这样修改你的代码可以解决这个问题:

if (dates[0].ToString() == day.ToString() || dates[1].ToString() == day.ToString() || dates[2].ToString() == day.ToString() || dates[3].ToString() == day.ToString())
{
return true;
}
else
{
return false;
}

效果是这样的:

enter image description here

关于android - 在 Xamarin.Android 中使用 MaterialCalendarView 绑定(bind)库添加装饰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45193268/

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