本文介绍了DatePickerDialog首先显示年份选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的DatePickerDialog打开后立即显示年份列表。

I want my DatePickerDialog as soon as it opens to display the list of years.

例如,当我显示对话框时,我会看到日历视图:

For example, when I show the dialog I see the calendar view::

如果我点击文本 1900显示了年份视图:

If I tap on the text "1900" the year view is shown:

我尝试了这段代码,但没有效果,我一无所知:
DatePickerDialog birthDatePicker = new DatePickerDialog(getActivity(),this,0, 0,0);
birthDatePicker.getDatePicker()。setSpinnersShown(true);
birthDatePicker.show();

I tried this code but it had no effect and I'm clueless for what I could do:DatePickerDialog birthDatePicker = new DatePickerDialog(getActivity(), this, 0, 0, 0); birthDatePicker.getDatePicker().setSpinnersShown(true); birthDatePicker.show();

推荐答案

使用Datepicker XML修改,您可以选择显示微调框而不是日历,这可能对您有利,因为您想直接编辑年份。

Using the Datepicker XML modifications you can elect to show spinners instead of the Calendar, which might be beneficial for you as you want to directly edit the years.

android:datePickerMode="spinner"

这篇关于DatePickerDialog首先显示年份选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 22:18