android - 如何以编程方式设置 datePickerMode ="spinner"?

标签 android datepicker

我需要以编程方式创建 DatePicker。而且我不能使用 xml 布局。我知道在 xml 中设置微调器 datePickerMode="spinner" 然后我可以使用 datePicker.setSpinnersShown(true);datePicker.setCalendarViewShown(false) 我尝试将 AttributeSet 添加到构造函数中,但我不知道如何使用它。 有人可以帮忙吗?如何在微调模式下创建 DataPicker?

谢谢

最佳答案

我已经找到一个帖子,它会描述你这个问题:

I have found a the explanation in the following post (which describes a problem very similar to mine) :

Android Material Design Inline Datepicker issue

In fact the setCalendarViewShown(false) and setSpinnersShown(true) are apparently not working anymore in latest versions.

We have to use an explicit XML attribute like this one android:datePickerMode="spinner".

The problem is that I'm using a DialogFragment without any XML layout (just a date picker dialog). So I cannot set any XML attribute.

The solution is to create a dedicated custom dialog with an XML layout file using the requested attribute.

FROM: Impossible to make my DatePickerDialog use a spinner style programmatically

希望对你有帮助

关于android - 如何以编程方式设置 datePickerMode ="spinner"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34723495/

相关文章:

android - 如何根据返回的标记计算缩放级别?

php - 将日期选择器字段添加到 WordPress 中的插件设置页面

javascript - 获取 jQuery UI 日期选择器中选定月份的天数

javascript - angularjs 部分 View 中的内部 javascript 不起作用?

android - 标题后退按钮 onCreate

android - 使用 ShareActionProvider-v7 的 ActionBar 上的 ShareAction 图标大小问题

android - PhoneGap Build 不显示启动画面

android - 广播 Intent 回调 : result=CANCELLED

ios 日期选择器到 unix 时间戳

javascript - 如何禁用 Angular Material 日期选择器中的特定日期