棒棒糖 [微调模式] 中没有日历可视化的日期选择器对话框? [英] Datepicker dialog without calendar visualization in lollipop [spinner mode]?
问题描述
我阅读了文档:http://developer.android.com/guide/topics/ui/controls/pickers.html但是现在在棒棒糖中出现日历(对于事件来说是可以的,但是对于设置出生日期来说很糟糕,我会使用微调模式.)而且我无法删除它!在布局中使用此属性很容易:
I read the documentation: http://developer.android.com/guide/topics/ui/controls/pickers.html but now in lollipop appears the calendar (it is ok for an event but horrible for set a date of birth, I would a spinner mode.) and I can't remove it! In layout It's easy with this property:
<DatePicker
datePickerMode="spinner"...>
但是如果我尝试设置,则来自 DatePickerDialog 的代码
but from code of the DatePickerDialog if I try to set
dialogDatePicker.getDatePicker().setSpinnersShown(true);
dialogDatePicker.getDatePicker().setCalendarViewShown(false);
这些属性不起作用,日历继续显示!
These properties do not work and the calendar continues to appear!
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 DatePickerDialog and return it
//return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
pYear = year;
pDay = day;
pMonth = month;
}
}
推荐答案
DatePickerDialog 使用您的活动主题指定的对话框主题.这是一个完全指定的主题,这意味着您需要重新指定您在活动主题中设置的任何属性(例如日期选择器样式).
DatePickerDialog uses the dialog theme specified by your activity theme. This is a fully-specified theme, which means you need to re-specify any attributes -- such as the date picker style -- that you've set in your activity theme.
<style name="MyAppTheme" parent="android:Theme.Material">
<item name="android:dialogTheme">@style/MyDialogTheme</item>
<item name="android:datePickerStyle">@style/MyDatePicker</item>
</style>
<style name="MyDialogTheme" parent="android:Theme.Material.Dialog">
<item name="android:datePickerStyle">@style/MyDatePicker</item>
</style>
<style name="MyDatePicker" parent="android:Widget.Material.DatePicker">
<item name="android:datePickerMode">spinner</item>
</style>
注意:由于问题 222208,这不适用于 Android N/API 24.它已在下一版本的平台中修复.没有适用于 API 24 设备的解决方法.
Note: Due to Issue 222208, this will not work in Android N / API 24. It has already been fixed in the platform for the next release. There is no workaround available for API 24 devices.
这篇关于棒棒糖 [微调模式] 中没有日历可视化的日期选择器对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!