在棒棒糖[微调模式]中没有日历可视化的Datepicker对话框? [英] Datepicker dialog without calendar visualization in lollipop [spinner mode]?

查看:305
本文介绍了在棒棒糖[微调模式]中没有日历可视化的Datepicker对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了文档: 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.

这篇关于在棒棒糖[微调模式]中没有日历可视化的Datepicker对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆