我有ScrollView一个Datepicker
在以前的Android版本中,Datepicker是这样的:

我可以滚动Datepicker日,月,年的单个元素没有问题
在Android Lollipop API level 21 Material中,Datepiker以这种方式显示:


如果我点击月份显示日历视图而我无法更改月份,我只能选择当天.如果我尝试编辑年份显示年份滚动条,但如果我尝试滚动它,则包含datepicker的整个布局将滚动,而不仅仅是日期.
calendarViewShown=false
Run Code Online (Sandbox Code Playgroud)
似乎被忽视了
我怎么能解决这个问题???
android datepicker android-datepicker datepickerdialog android-5.0-lollipop
我阅读了文档:http://developer.android.com/guide/topics/ui/controls/pickers.html 但是现在在棒棒糖中出现了日历(这对于一个活动来说还可以,但是设定出生日期可怕,我将旋转模式.)我无法删除它!在布局中使用此属性很容易:
<DatePicker
datePickerMode="spinner"...>
Run Code Online (Sandbox Code Playgroud)
但是如果我尝试设置,则从DatePickerDialog的代码
dialogDatePicker.getDatePicker().setSpinnersShown(true);
dialogDatePicker.getDatePicker().setCalendarViewShown(false);
Run Code Online (Sandbox Code Playgroud)
这些属性不起作用,日历继续出现!
public static class MyDatePicker extends DialogFragment implements DatePickerDialog.OnDateSetListener {
int pYear;
int pDay;
int pMonth;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialogDatePicker = new DatePickerDialog(getActivity(), this, year, month, day);
dialogDatePicker.getDatePicker().setSpinnersShown(true);
dialogDatePicker.getDatePicker().setCalendarViewShown(false);
return dialogDatePicker;
// Create a new instance of …Run Code Online (Sandbox Code Playgroud) 我正在用一个DialogFragment打开一个DatePickerDialog
public class DatePickerFragment extends DialogFragment{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
DatePickerDialog DatePickerDialog = new DatePickerDialog(getActivity(), (ProfileCreationActivity)getActivity(), year, month, day);
return DatePickerDialog;
}
Run Code Online (Sandbox Code Playgroud)
我正在看日历外观,我更喜欢旋转外观.
我试过了:
datePickerDialog.getDatePicker().setCalendarViewShown(false);
Run Code Online (Sandbox Code Playgroud)
和
datePickerDialog.getDatePicker().setLayoutMode(1);
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
请注意,我希望微调器查找一个活动,但我希望其他活动的日历视图.所以我无法改变整个应用程序的风格.我需要一个活动的自定义样式.
我想在DialogFragment中显示一个DatePicker:
public class DatePickerDialogFragment extends DialogFragment {
private OnDateSetListener dateSetListener = null;
private String title = null;
public DatePickerDialogFragment() {}
public DatePickerDialogFragment(OnDateSetListener dateSetListener, String title) {
this.dateSetListener = dateSetListener;
this.title = title;
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(this.getActivity(), this.dateSetListener, year, month, day);
datePickerDialog.getDatePicker().setCalendarViewShown(false);
datePickerDialog.setTitle(this.title);
return datePickerDialog;
}
}
Run Code Online (Sandbox Code Playgroud)
遗憾的datePickerDialog.getDatePicker().setCalendarViewShown(false);是完全被忽略了.我讨厌日历视图,因为它很丑陋且不舒服.那我怎么能禁用它呢?