Reputation: 11
In the image above (don't worry about the calendar positioning), the whole calendar is the correct theme color except the green of the chosen date. I've tried many things but not been able to change this last part of the theme! I'm using Theme.AppCompat.Light.DarkActionBar and have gotten to the current point by changing the DatePickerDialogTheme's colorAccent. I've also tried changing
And those don't seem to have done it. Here's my XML, thank you in advance!
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorRed</item>
<item name="colorPrimaryDark">@color/colorRed</item>
<item name="colorAccent">@color/colorRed</item>
<item name="android:datePickerDialogTheme">@style/MyDatePickerDialogTheme</item>
</style>
<style name="MyDatePickerDialogTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:colorAccent">@color/colorRed</item>
</style>
Upvotes: 1
Views: 5349
Reputation: 635
For the selected day's colour you do have to use colorAccent, here's what works me:
<style name="PopupDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<!--selected day's color: define your own-->
<item name="colorAccent">@color/yourColour</item>
</style>
and in your class instantiate like this:
final AlertDialog.Builder datePickerBuilder = new AlertDialog.Builder(ProviderMainActivity.this, R.style.PopupDialogTheme);
// ... do something with your dialog, i.e. .show()
Regarding the other attributes that were mentioned in the question: look up their reference and find out what params they take (in the xml). For example for setting the year/month/day's colour in the header, you have to define a text appearance (CodeFont) like this:
<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dpPickDate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:headerBackground="@drawable/calendar_header"
android:headerYearTextAppearance="@style/YourCodeFont"
android:headerMonthTextAppearance="@style/YourCodeFont"
android:headerDayOfMonthTextAppearance="@style/YourCodeFont"/>
note YourCodeFont, which you need to define in your styles.xml
:
<style name="PopupCodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/black</item>
</style>
You can't, for example do this:
android:headerYearTextAppearance="@color/black"
Also note that some of these attributes, in example headerYearTextAppearance
require API 21+, so better handle and test for previous versions.
Upvotes: 0
Reputation: 230
To change the colour of the circle of the selected date, use
<item name="android:colorControlActivated">@color/your_colour</item>
Upvotes: 2
Reputation: 8638
use this theme
<style name="MyDatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:colorAccent">@color/colorRed</item>
<item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
<item name="android:colorAccent">@color/primaryDark</item>
</style>
and
<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
<item name="android:headerBackground">@color/primary</item>
<item name="android:calendarTextColor">@color/primaryDark</item>
<item name="android:dayOfWeekBackground">@color/primaryDark</item>
<item name="android:yearListSelectorColor">@color/accent</item>
<item name="android:datePickerMode">calendar</item>
</style>
Upvotes: 0