prolificinteractive / material-calendarview

A Material design back port of Android's CalendarView
https://prolificinteractive.github.io/material-calendarview/
MIT License
5.91k stars 1.32k forks source link

Is possible to change selected day text color? #85

Closed marabita closed 9 years ago

marabita commented 9 years ago

First thanks for the component, is excellent and very complete.

I'm trying to change the text color of the selected day and just found the setSelectionColor property but it changes the color of the round form.

dandc87 commented 9 years ago

You can use app:mcv_dateTextAppearance (or the Java setter) to do this. I still need to document how this should be done ( #76 ), but for now you can copy the default implementation and modify as you need. Essentially you need to supply a android:textColor that is a color state list with your desired colors.

Add a style:

<style name="TextAppearance.MyCustomDay" parent="android:TextAppearance.DeviceDefault.Small">
    <item name="android:textSize">12sp</item>
    <item name="android:textColor">@color/my_custom_day_color</item>
</style>

and create color/my_custom_day_color.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
    android:enterFadeDuration="@android:integer/config_shortAnimTime"
    android:exitFadeDuration="@android:integer/config_shortAnimTime">

    <item android:state_checked="true" android:color="SELECTION_COLOR" />
    <item android:state_pressed="true" android:color="SELECTION_COLOR" />
    <item android:state_enabled="false"  android:color="#808080" />
    <item android:color="@android:color/black" />
</selector>

then set app:mcv_dateTextAppearance="@style/TextAppearance.MyCustomDay"

marabita commented 9 years ago

Hi @dandc87, Thanks for very fast response I resolved using a decoration specific to change the selected date:

public class OneDayDecorator implements DayViewDecorator {

    private CalendarDay date;

    public OneDayDecorator() {
        date = CalendarDay.today();
    }

    @Override
    public boolean shouldDecorate(CalendarDay day) {
        return date != null && day.equals(date);
    }

    @Override
    public void decorate(DayViewFacade view) {
        view.addSpan(new ForegroundColorSpan(Color.RED));
    }

    /**
     * We're changing the internals, so make sure to call {@linkplain MaterialCalendarView#invalidateDecorators()}
     */
    public void setDate(Date date) {
        this.date = CalendarDay.from(date);
    }
} 

And adding on calendar view:

        mCalendarView.addDecorator(mSelectedDayDecorator);
Studentessa commented 8 years ago

@Marabita! your solution works for me! thanks!

haiho commented 7 years ago

thanks @Marabita , I has been highlight current day, i happy

Kharlos commented 6 years ago

Great its work! and if u want use custom color I add context in OneDayDecorator and use

view.addSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.celeste)));

tsdmrfth commented 6 years ago

Hello @Marabita . I am trying to use your solution but I guess I do not fully understand your solution. I created decorator class and set it to my calendar view but the result is still the same. Can you help me please..

giancarloap commented 6 years ago

@dandc87 Works like a charm. Thanks!

Sathyan-Elangovan commented 3 years ago

@marcello-marabita-mblabs Thanks it works for me.