Is it possible to change the datepicker (and also the timepicker) colour scheme for android 5.0?
I've tryed setting the accent colours, but this doesn't work (both with and without android:
):
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/purple</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/purple_tint</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">@color/purple_tint</item>
From original:
To something like this:
For Changing Year list item text color (SPECIFIC FOR ANDROID 5.0)
Just set certain text color in your date picker dialog style. For some reason setting flag
yearListItemTextAppearance
doesn't reflect any change on year list.The reason why Neil's suggestion results in a fullscreen
DatePicker
is the choice of parent theme:Moreover, if you go this route, you have to specify the theme while creating the
DatePickerDialog
:This, in my opinion, is not good. One should try to keep the styling out of java and inside styles.xml/themes.xml.
I do agree that Neil's suggestion, with a bit of change (changing the parent theme to say,
Theme.Material.Light.Dialog
) will get you the desired result. But, here's the other way:On first inspection, we come across
datePickerStyle
which defines things such as:headerBackground
(what you are trying to change),dayOfWeekBackground
, and a few other text-colors and text-styles.Overriding this attribute in your app's theme will not work.
DatePickerDialog
uses a separate theme assignable by the attributedatePickerDialogTheme
. So, for our changes to take affect, we must overridedatePickerStyle
inside an overridendatePickerDialogTheme
.Here we go:
Override
datePickerDialogTheme
inside your app's base theme:Define
MyDatePickerDialogTheme
. The choice of parent theme will depend on what your app's base theme is: it could be eitherTheme.Material.Dialog
orTheme.Material.Light.Dialog
:We have overridden
datePickerStyle
with the styleMyDatePickerStyle
. The choice of parent will once again depend on what your app's base theme is: eitherWidget.Material.DatePicker
orWidget.Material.Light.DatePicker
. Define it as per your requirements:Currently, we are only overriding
headerBackground
which by default is set to?attr/colorAccent
(this is also why Neil suggestion works in changing the background). But there's quite a lot of customization possible:If you don't want this much control (customization), you don't need to override
datePickerStyle
.colorAccent
controls most of theDatePicker's
colors. So, overriding justcolorAccent
insideMyDatePickerDialogTheme
should work:Overriding
colorAccent
gives you the added benefit of changingOK
&CANCEL
text colors as well. Not bad.This way you don't have to provide any styling information to
DatePickerDialog's
constructor. Everything has been wired properly:try this, work for me
Put the two options,
colorAccent
andandroid:colorAccent
Create a new style
Java code:
The parent theme is the key here. Choose your colorAccent
Result:
Give this a try.
The code
The Style In your styles.xml file
EDIT - Changed theme to Theme.AppCompat.Light.Dialog as suggested
You don't have create theme just write it in your dialog creation object
follow this it will give you all type date picker style it's really work
http://www.android-examples.com/change-datepickerdialog-theme-in-android-using-dialogfragment/