我需要以编程方式创建 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/