Android 6.0 DatePickerDialog Theme

It seems that anyone using Marshmallow (Android 6.0) cannot use DatePicketDialog in my application. There seems to be some kind of topic that I come across. I am using DialogFragment which contains DatePicketDialog so that user can select birthday. Here are the snapshots of DialogFragment with Android 5.x and d 6.x.

Android 5.x Android 6.x

I tried to add a theme to the DatePickerDialog constructor, but did the full screen mode DialogFragment , and I don't want that. Does anyone know how I can make DatePickerDialog look like it was before Marshmallow?

UPDATE 1

Here is the code in which I create the DialogFragment :

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

Here is the onCreateDialog inside 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 theme.xml, the only line that deals with Dialogs is

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

But if I think correctly, it does not concern DialogFragment does?

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> 
+6
source share
3 answers

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

+4
source

Just change the colorAscent color in .xml styles :

 <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> 
+4
source

You create a theme in styles.xml but don't refer to DatePickerDialog as

 DatePickerDialog dlg = new DatePickerDialog(getActivity(), R.style.datepickerCustom,this,year,month,day); 

and create a name for the values-v21 and add a copy of style.xml to it. and paste

 <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> 
+3
source

All Articles