在datepicker中设置最大日期时,可以选择将来的日期 [英] Able to choose future date when setting max date in datepicker

查看:737
本文介绍了在datepicker中设置最大日期时,可以选择将来的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AppCompat v21来定位和构建API 21级。

I'm targeting for and building with API level 21, using AppCompat v21.

它给了我一个很好看的新的日期选择器,它具有意想不到的属性允许我选择最大日期的未来日期已经使用

It gives me a nicely looking new date picker, which has the unexpected property of allowing me to choose a future date when max date has been set using

datePicker.setMaxDate(Calendar.getInstance().getTimeInMillis())

未来的日期是灰色的,但我仍然可以选择任何一个。这是一个bug吗?我做错了吗有没有办法阻止用户在日期选择器中选择未来的日期?

The future dates are greyed out, but I can still choose any one of them. Is that a bug? Am I doing it wrong? Is there a way to prevent the user from being able to pick a future date in the date picker?

旧的Holo日期选择器在设置时未能选择未来的日期最高日期。

The old Holo date picker did not allow picking a future date when setting a maximum date.

更新:

虽然它不能正常工作我的Nexus 4运行股票5.0,它正在我的Nexus 6运行股票Android 5.1.1正常工作。也许这是Android 5.0中的一个bug,它在5.1中修复了吗?任何人都可以确认?

While it is not working properly on my Nexus 4 running stock 5.0, it is working properly on my Nexus 6 running stock Android 5.1.1. Perhaps it was a bug in Android 5.0 and it was fixed in 5.1? Can anyone confirm?

推荐答案

所以回答我自己的问题:

So to answer my own question:

我在grepcode中查看了 DatePickerCalendarDelegate.java 的Android源代码,特别是 public void setMaxDate(long maxDate)两个Android版本 5.0 5.1

I've looked at the Android source of DatePickerCalendarDelegate.java at grepcode, specifically at public void setMaxDate(long maxDate) for both Android versions 5.0 and 5.1.

setMaxDate() 5.1中的新功能是

What's new in 5.1 in setMaxDate() is that

mDayPickerView.goTo(getSelectedDay ),false,true,true);

已更改为:

mDayPickerV iew.setMaxDate(maxDate);

它似乎固定在那里,这对应于我的观察结果,它在5.1中的预期工作,但不符合在5.0。

It seems they fixed it there, which corresponds with my observation that it works as expected in 5.1 but not in 5.0.

所以似乎我们坚持处理这样的事实,它在Android 5.0中无法正常工作(最大日期之后的几天是灰色的,但是仍然可以选择)。

And so it seems we're stuck with dealing with the fact that it doesn't work properly in Android 5.0 (days after max date are greyed out but can still be chosen).

这篇关于在datepicker中设置最大日期时,可以选择将来的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆