The reason the Neil clause leads to the full-screen DatePicker screen is to choose the parent theme:
<style name="DialogTheme" parent="**Theme.AppCompat.Light**"> <item name="colorAccent">@color/blue_500</item> </style>
In addition, if you are following this route, you must specify the topic when creating the DatePickerDialog :
// R.style.DialogTheme new DatePickerDialog(MainActivity.this, R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { //DO SOMETHING } }, 2015, 02, 26).show();
This, in my opinion, is not very good. You need to try to save the style from java and inside styles.xml / themes.xml.
I agree that the Neil proposal with a slight change (changing the parent theme to say Theme.Material.Light.Dialog ) will give you the desired result. But otherwise:
On first inspection, we come across a datePickerStyle that defines things like: headerBackground (what you are trying to change), dayOfWeekBackground and several other text colors and text styles.
Overriding this attribute in the application theme will not work. DatePickerDialog uses a separate topic, assigned by the datePickerDialogTheme attribute. So, for our changes to affect, we have to override datePickerStyle inside the override of datePickerDialogTheme .
Here we go:
Override datePickerDialogTheme inside your application’s main theme:
<style name="AppBaseTheme" parent="android:Theme.Material.Light"> .... <item name="android:datePickerDialogTheme">@style/MyDatePickerDialogTheme</item> </style>
Define MyDatePickerDialogTheme . The choice of the parent theme will depend on what your base theme for the application is: it can be either Theme.Material.Dialog or Theme.Material.Light.Dialog :
<style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog"> <item name="android:datePickerStyle">@style/MyDatePickerStyle</item> </style>
We redefined datePickerStyle with MyDatePickerStyle style. The choice of parent will again depend on what your base theme for your application is: either Widget.Material.DatePicker , or Widget.Material.Light.DatePicker . Define it according to your requirements:
<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker"> <item name="android:headerBackground">@color/chosen_header_bg_color</item> </style>
Currently, we are only redefining the headerBackground , which defaults to ?attr/colorAccent (this is also due to the fact that the Neil clause works when changing the background). But there are quite a few settings:
dayOfWeekBackground dayOfWeekTextAppearance headerMonthTextAppearance headerDayOfMonthTextAppearance headerYearTextAppearance headerSelectedTextColor yearListItemTextAppearance yearListSelectorColor calendarTextColor calendarSelectedTextColor
If you do not want this big control (settings), you do not need to redefine datePickerStyle . colorAccent controls most DatePicker's colors. So, overriding only colorAccent inside MyDatePickerDialogTheme should work:
<style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog"> <item name="android:colorAccent">@color/date_picker_accent</item> </style>
Overriding colorAccent gives you the added benefit of changing the colors of OK and CANCEL text. Not bad.
This way you do not need to provide any style information to DatePickerDialog's constructor. Everything is correctly connected:
DatePickerDialog dpd = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { } }, 2015, 5, 22); dpd.show();