DatePicker color style for Android
I want to change the default "green" color of a Material Design DatePicker using AppCompat, but I couldn't find anything.
I tried to do something like this, but no results:
<item name="android:datePickerStyle">#00BCD4</item>
This other way does not allow me to change color because minSdkVersion ..
<item name="android:calendarTextColor">#00BCD4</item>
Is it possible to change the color for all Android versions from API 15 to 21?
source to share
Here's how to get the purple and orange colors in the image below.
Create your own theme for your DatePicker in styles.xml:
<style name="MyDatePickerTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@android:color/holo_purple</item>
<item name="android:windowBackground">@drawable/date_picker_background</item>
</style>
Note that this theme references a custom background for the date picker in the resource resource folder. So create a resource named date_picker_background.xml and put it in it:
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="16dp"
android:insetTop="16dp"
android:insetRight="16dp"
android:insetBottom="16dp">
<shape android:shape="rectangle">
<corners android:radius="2dp" />
<solid android:color="@android:color/holo_orange_dark" />
</shape>
</inset>
Finally, you should refer to this topic when instantiating the DatePickerDialog:
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(),
R.style.MyDatePickerTheme, this, year, month, day);
My explanation here was adapted from this better, more complete explanation of the DatePicker style.
source to share