如何在 DatePicker 中关闭 CalendarView? [英] How to turn off CalendarView in a DatePicker?
问题描述
在我的设置屏幕上,我有一个日期选择器小部件.在 Eclipse 的设计器中,它按我的意愿显示(D-M-Y 的 3 个微调器)但是当我在我的设备上进行测试时,我得到了一个相当奇怪的视图,左侧有一个侧向微调器,右侧有一个日历.以前从未见过这个(!)但做了一些研究,我想我看到了CalendarView".
On my settings screen I have a date picker widget. In the designer in Eclipse, it shows as I want (3 spinners for D-M-Y) but when I test on my device, I get a rather odd view with a side spinner on the left and a calendar on the right. Never seen this before(!) but doing some research I think I'm seeing the "CalendarView".
我发现我应该能够将calendarViewShown"属性设置为 false - 但我的 XML 会因此引发错误.我在这里发现了另一个问题,表明 API 级别是罪魁祸首(我的 minSDKLevel 是 7,但我的目标是 11,所以我可以获得操作栏按钮而不是 oldskool 菜单).所以我想我会尝试在代码中设置它:
I found that I should be able to set a "calendarViewShown" property to false- but my XML throws an error with this. I found another question on here that suggested the API level was to blame (my minSDKLevel is 7, but I'm targetting 11 so I can get the action bar button rather than the oldskool menu). So I thought I'd try setting it in code:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= 11)
minDateSelector.setCalendarViewShown = false;
但是,这又失败了——没有找到 setCalendarViewShown.但是文档 here 说它应该存在.有什么想法吗?!
But again, this fails- setCalendarViewShown isn't found. But the docs here say it should exist. Any ideas?!
推荐答案
如果您的目标是更高版本的 API,您可以在您的
:
If you are targeting a later version of the API, you can use the following XML (no need to write Java code) in your <DatePicker>
:
android:calendarViewShown="false"
这篇关于如何在 DatePicker 中关闭 CalendarView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!