Android 6.0 DatePickerDialog主题

Mik*_*ker 6 android themes datepickerdialog dialogfragment

似乎任何使用Marshmallow(Android 6.0)的人都无法DatePicketDialog在我的应用程序中使用.似乎遇到了某种我遇到的主题问题.我用一个DialogFragment包含一个DatePicketDialog供用户选择生日.以下是Android 5.x和6.x的DialogFragment镜头.

Android 5.x Android 6.x

我试图在DatePickerDialog构造函数中添加一个主题,但这使得DialogFragment全屏,我不希望这样.有谁知道我怎么能看到DatePickerDialog它像棉花糖之前?

更新1

这是我创建的代码DialogFragment:

DialogFragment ageFragment = new DatePickerDialogFragment();
ageFragment.show(getFragmentManager(), "datePicker");
Run Code Online (Sandbox Code Playgroud)

这是onCreateDialog里面的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;
}
Run Code Online (Sandbox Code Playgroud)

在themes.xml中,唯一触及的行Dialogs是

<item name="android:alertDialogTheme">@style/CustomDialogTheme</item>
Run Code Online (Sandbox Code Playgroud)

但如果我正在思考,那不会触及DialogFragment吗?

更新2

这是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>
Run Code Online (Sandbox Code Playgroud)

Xar*_*mer 6

您在创建主题styles.xml,但没有提到它DatePickerDialog喜欢

DatePickerDialog dlg = new DatePickerDialog(getActivity(),
                R.style.datepickerCustom,this,year,month,day);
Run Code Online (Sandbox Code Playgroud)

并创建一个文件夹名称values-v21并向其中添加一个副本style.xml。并粘贴

<style name="datepickerCustom" parent="@android:style/Theme.DeviceDefault.Light.Dialog">
        <item name="android:colorAccent">@color/orange_theme</item>
        <item name="android:windowBackground">@android:color/darker_gray</item>
        <!--<item name="android:windowContentOverlay">@null</item>-->
        <!--<item name="android:textColorPrimary">@color/white</item>-->
        <!--<item name="android:textColorSecondary">@color/white</item>-->
    </style>
Run Code Online (Sandbox Code Playgroud)


Luf*_*ffy 5

只需更改样式.xml 中的colorAscent颜色:

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">

    <item name="colorAccent">#FC6C2D</item>   ---> I used orange color here to display the picker dialog in orange color for marshmallow device.

    <item name="android:textColorPrimary">#000000</item>
    <item name="android:textColorSecondary">#000000</item>

</style>
Run Code Online (Sandbox Code Playgroud)


Mik*_*ker 4

感谢帖子How to Change the style of Date picker in android? ,我能够正确地展示DatePicker. parent="Theme.AppCompat.Light.Dialog"我在设计时必须使用DatePicker