calendarview突出显示错误的一周

calendarview突出显示错误的一周

问题描述:

我的应用程序中有一个CalendarView,当用户通过触摸月视图中的日期来选择日期时,会选择正确的日期(通过在代码中添加调试语句进行验证),但是突出显示了前一周,因此好像选择了错误的日期.

I have a CalendarView in my app, when the user selects a date by touching that date in the monthview, the correct date is selected (verified by adding debug statements in the code), but the week before is highlighted, so it looks as if the wrong date is selected.

我找到了一种解决方法:如果将"firstDayInWeek"设置为1,则问题得以解决,但是默认情况下,firstDayInweek为2(星期一),然后会出现此问题.

I have found a work-around: if I set 'firstDayInWeek' to 1 the problem is solved, but by default the firstDayInweek is 2 (monday), and then this problem occurs.

非常感谢!

具有API 21的三星S4

Samsung S4 with API 21

使用运行API 21的Samsung S5,我遇到了与您相同的问题.

I have had the same issue as you, using a Samsung S5 running API 21.

我发现了两种解决方法,它们都不会对我们的用户带来良好的体验:(

There are two workarounds that I have found, none of them is a good experience for our users :(

  1. 将一周的第一天强制为星期日


    calendarView.setFirstDayOfTheWeek(Calendar.SUNDAY);

  1. 设置日历的最小和最大日期(请注意,因为并非所有日期都在这里工作).我能够使其正常工作,将当前日期前的最短日期设置为2个月,将当前日期后的最长时间设置为2年.您可以使用这些值,并在限制和用户体验之间找到良好的折衷.


    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 2);
    calendarView.setMinDate(calendar.getTimeInMillis());
    calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 2);
    calendarView.setMaxDate(calendar.getTimeInMillis());

不幸的是,这是我可以解决此问题的唯一方法,希望对您有用.

Unfortunately, this is the only way I could fix this issue, I hope it is useful for you.