Vintally Official
Vintally Official

Reputation: 85

How to change Spinner datepicker color? - Android Studio

I've been trying for more than half an hour to change the default date picker color to a color I want, but I can't, I've searched on internet forums, but I can't find a solution that solves my problem.

This is my datepicker:

enter image description here

This is more or less the result I want to get:

enter image description here

I made the datepicker in xml, and I want it to stay in xml anyway

<DatePicker
                android:id="@+id/date_picker"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:datePickerMode="spinner"
                android:layout_marginTop="20dp"
                style="@style/RYZZE_DATE_PICKER"
                android:layout_marginBottom="40dp"
                android:layout_centerHorizontal="true"
                android:calendarViewShown="false"/>

style:

    <style name="RYZZE_DATE_PICKER">
        <item name="android:textColorPrimary">#ff00ff</item>
        <item name="android:colorControlNormal">#ff00ff</item>
        <item name="colorAccent">#ff00ff</item>
    </style>

Upvotes: 0

Views: 957

Answers (2)

Mayur Gajra
Mayur Gajra

Reputation: 9073

You need to change style to android:theme in DatePicker.

as following:

<DatePicker
        android:id="@+id/date_picker"
        android:theme="@style/RYZZE_DATE_PICKER"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:calendarViewShown="false"
        android:datePickerMode="spinner"
        />

To change the horizontal bars color you need to change colorControlNormal & to change date text color you need to change textColorPrimary as following.

<style name="RYZZE_DATE_PICKER">
        <item name="android:textColorPrimary">#00796B</item>
        <item name="android:colorControlNormal">#FBC02D</item>
    </style> 

Following is the result:

datepickercustom

Upvotes: 0

Noban Hasan
Noban Hasan

Reputation: 713

You can use this.

          <DatePicker
                android:id="@+id/date_picker"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:datePickerMode="spinner"
                android:layout_marginTop="20dp"
                android:theme="@style/RYZZE_DATE_PICKER"
                android:layout_marginBottom="40dp"
                android:layout_centerHorizontal="true"
                android:calendarViewShown="false"/>

Upvotes: 1

Related Questions