如何设置 datePickerMode="spinner"以编程方式? [英] How to set datePickerMode="spinner" programmatically?
问题描述
我需要以编程方式创建 DatePicker.而且我不能使用 xml 布局.我知道在 xml 中设置微调器 datePickerMode="spinner"
然后我可以使用 datePicker.setSpinnersShown(true);
和 datePicker.setCalendarViewShown(false)
我尝试将 AttributeSet
添加到构造函数中,但我不知道如何使用它.有人可以帮忙吗?如何在 Spinner 模式下创建 DataPicker?
I need create DatePicker programmatically. And i can't use xml layout. i know set spinner in xml datePickerMode="spinner"
and then i can use datePicker.setSpinnersShown(true);
and datePicker.setCalendarViewShown(false)
I try add AttributeSet
into constructor but i don't know how use it.
Can someone help? How to create a DataPicker in spinner mode?
谢谢
推荐答案
我已经找到一个帖子,它会描述你这个问题:
I've already found a post, which it would describe you this problem:
我在以下帖子中找到了解释(其中描述了一个与我非常相似的问题):
I have found a the explanation in the following post (which describes a problem very similar to mine) :
Android Material Design 内联日期选择器问题
实际上 setCalendarViewShown(false) 和 setSpinnersShown(true) 是显然在最新版本中不再工作了.
In fact the setCalendarViewShown(false) and setSpinnersShown(true) are apparently not working anymore in latest versions.
我们必须使用像这样的显式 XML 属性android:datePickerMode=微调器".
We have to use an explicit XML attribute like this one android:datePickerMode="spinner".
问题是我使用的是没有任何 XML 布局的 DialogFragment(只是一个日期选择器对话框).所以我不能设置任何 XML 属性.
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.
解决方案是创建一个具有 XML 布局的专用自定义对话框使用请求的属性的文件.
The solution is to create a dedicated custom dialog with an XML layout file using the requested attribute.
来自:不可能让我的 DatePickerDialog 使用以编程方式微调样式
希望对你有帮助
这篇关于如何设置 datePickerMode="spinner"以编程方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!