gregkorossy / DateTimePicker

Material themed DateTimePickers from the Android framework for all API levels (API 14+)
Apache License 2.0
73 stars 17 forks source link

Can't override colorAccent? #1

Open 0megaD opened 6 years ago

0megaD commented 6 years ago

I might be missing some nuance due to using this library, but I couldn't figure out how to override colorAccent.

The reason for this is because I want to change the color of the overall datepicker, without propagating those changes throughout the rest of the app.

Am I missing something or does this truly not work:

    <style name="datepicker" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">#FF0000</item>
    </style>

...

    <com.takisoft.datetimepicker.widget.DatePicker
        android:id="@+id/date_picker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/datepicker"
        />

I also tried setting the style attributes from your readme, with similar results (or a lack of, rather)

An alternative would be to change all the colors of the datepicker manually, but I couldn't figure out the attribute for the selected day indicator, only for the other colored components.

gregkorossy commented 6 years ago

Sorry, didn't see this message (apparently GitHub doesn't subscribe me to my own repo automatically...).

Well, the colorAccent is coming from the theme (using ?colorAccent). Maybe try using the theme attribute instead of style? Also, the com.takisoft.datetimepicker.widget.DatePicker is a widget, not a dialog, so you should use Widget.Material.DatePicker or Widget.Material.Light.DatePicker as the parent.

gregkorossy commented 6 years ago

Okay, so I checked out the things and here is the situation: The day selector's color comes from Widget.Material.CalendarView. If you check out out the styles_material.xml file, you'll see that it has a dtp_daySelectorColor attribute that sets it. This is set to ?attr/colorControlActivated by default which gets set from the theme according to the accent color. You can try overriding the chain (style for the DatePicker extending Widget.Material.DatePicker -> set calendarViewStyle to your style extending Widget.Material.CalendarView -> dtp_daySelectorColor) to achieve what you want or set the theme on the DatePicker.

0megaD commented 6 years ago

Thanks for your reply, I will try out your suggestions when I have the time. :)