在Android 6.0 DatePickerDialog主题 [英] Android 6.0 DatePickerDialog Theme

查看:2379
本文介绍了在Android 6.0 DatePickerDialog主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像使用棉花糖(在Android 6.0)任何人都不能到我的应用程序中使用 DatePicketDialog 。似乎有某种主题的问题,我现在遇到。我用的是 DialogFragment 包含一个 DatePicketDialog 供用户选择生日。下面是与Android的DialogFragment投5.X的ð6.x中

Android的5.x的

我试图在 DatePickerDialog 构造函数添加一个主题,但取得了 DialogFragment 全屏和我不不想说。有谁知道我怎么能获得 DatePickerDialog 看起来像棉花糖来之前,它是什么?

更新1

下面是code,我创建 DialogFragment

  DialogFragment ageFragment =新DatePickerDialogFragment();
ageFragment.show(getFragmentManager(),日期选择器);

下面是 onCreateDialog 中的 DatePickerDialogFragment

  @覆盖
公共对话框onCreateDialog(捆绑savedInstanceState){
    如果没有过滤器设置//使用当前日期作为选择器的默认日期
    日历CAL = Calendar.getInstance();
    //设置日期18年previous,因为只有18岁以上的被允许的应用程序
    cal.add(Calendar.YEAR,-18);
    INT年,月,日;
    如果(iDialogListener.getYear()== -1 || iDialogListener.getMonth()== -1
            || iDialogListener.getDay()== - 1){
        日历defaultCal = Calendar.getInstance();
        // 40是默认的年龄,以显示
        defaultCal.add(Calendar.YEAR,-40);
        年= defaultCal.get(Calendar.YEAR);
        月= defaultCal.get(的Calendar.MONTH);
        天= defaultCal.get(Calendar.DAY_OF_MONTH);
    }其他{
        年= iDialogListener.getYear();
        一个月= iDialogListener.getMonth();
        天= iDialogListener.getDay();
    }    DatePickerDialog日期选择器=新DatePickerDialog(getActivity(),这,年,月,日);
    。datepicker.getDatePicker()setMaxDate(cal.getTimeInMillis());
    日历MINDATE = Calendar.getInstance();
    minDate.set(Calendar.YEAR,Calendar.getInstance()获得(Calendar.YEAR) - 100);
    。datepicker.getDatePicker()setMinDate(minDate.getTimeInMillis());    //创建DatePickerDialog的新实例,并将其返回
    返回日期选择器;
}

在的themes.xml触及唯一的行对话框

 <项目名称=机器人:alertDialogTheme> @风格/ CustomDialogTheme< /项目>

但是,如果我想的权利,这不触及 DialogFragment 不是吗?

更新2

下面是 CustomDialogTheme

 <样式名称=CustomDialogTheme父=@安卓风格/ Theme.Holo.Light.Dialog>
    <项目名称=机器人:windowBackground> @android:彩色/透明< /项目>
    <项目名称=机器人:windowContentOverlay> @空< /项目>
    <项目名称=机器人:windowMinWidthMajor> @android:扪/ dialog_min_width_major< /项目>
    <项目名称=机器人:windowMinWidthMinor> @android:扪/ dialog_min_width_minor< /项目>
< /风格>


解决方案

由于该职位<一个href=\"http://stackoverflow.com/questions/30239627/how-to-change-the-style-of-date-picker-in-android\">How更改日期选择器的风格在android系统?,我能够正确显示的DatePicker 。我不得不使用父=Theme.AppCompat.Light.Dialog造型时,的DatePicker

Seems like anyone using Marshmallow (Android 6.0) is not able to use the DatePicketDialog within my app. There appears to be some sort of theme issue that I'm encountering. I use a DialogFragment which contains a DatePicketDialog for the user to select birthday. Here are shots of the DialogFragment with Android 5.x an d 6.x.

I attempted to add a theme in the DatePickerDialog constructor, but that made the DialogFragment fullscreen and I don't want that. Does anyone know how I can get the DatePickerDialog to look like it was prior to Marshmallow?

UPDATE 1

Here is the code where I create the DialogFragment:

DialogFragment ageFragment = new DatePickerDialogFragment();
ageFragment.show(getFragmentManager(), "datePicker");

Here is the onCreateDialog inside the DatePickerDialogFragment:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current date as the default date in the picker if no filters are set
    Calendar cal = Calendar.getInstance();
    // Set the date 18 years previous, since only 18 and older are allowed on the app
    cal.add(Calendar.YEAR, -18);
    int year, month, day;
    if (iDialogListener.getYear() == -1 || iDialogListener.getMonth() == -1
            || iDialogListener.getDay() == -1) {
        Calendar defaultCal = Calendar.getInstance();
        // 40 is the default age to show
        defaultCal.add(Calendar.YEAR, -40);
        year = defaultCal.get(Calendar.YEAR);
        month = defaultCal.get(Calendar.MONTH);
        day = defaultCal.get(Calendar.DAY_OF_MONTH);
    } else {
        year = iDialogListener.getYear();
        month = iDialogListener.getMonth();
        day = iDialogListener.getDay();
    }

    DatePickerDialog datepicker = new DatePickerDialog(getActivity(), this, year, month, day);
    datepicker.getDatePicker().setMaxDate(cal.getTimeInMillis());
    Calendar minDate = Calendar.getInstance();
    minDate.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR) - 100);
    datepicker.getDatePicker().setMinDate(minDate.getTimeInMillis());

    // Create a new instance of DatePickerDialog and return it
    return datepicker;
}

In the themes.xml the only line that touches Dialogs is

<item name="android:alertDialogTheme">@style/CustomDialogTheme</item>

But if I'm thinking right, that doesn't touch the DialogFragment does it?

Update 2

Here is the CustomDialogTheme:

<style name="CustomDialogTheme" parent="@android:style/Theme.Holo.Light.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
    <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>

解决方案

Thanks to the post How to change the style of Date picker in android?, I was able to properly show the DatePicker. I had to use parent="Theme.AppCompat.Light.Dialog" when styling the DatePicker

这篇关于在Android 6.0 DatePickerDialog主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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