Android calendar view date color

房东的猫 提交于 2019-12-08 23:12:34

Your best bet might be to create your own CalendarView class i.e. CalendarViewCustom based on the source code found here.

You could then add an extra method to the LegacyCalendarViewDelegate class similar to the setFocusedMonthDateColor() method to iterate through the weeks and set a date and colour in the WeekView class (might be worth storing these key/value date/colours as an Map collection instance variable in the WeekView class). e.g.

public void setMonthDateColor(Date date, int color) {                
    final int childCount = mListView.getChildCount();
    for (int i = 0; i < childCount; i++) {
        WeekView weekView = (WeekView) mListView.getChildAt(i);
        if (weekView.isDateInWeek(date)) {
            //this method adds the date and colour to a 
            //Map collection in weekView Object 
            weekView.setDateColour(date, color);
        }
    }
}

The above method then needs to be exposed by adding another method to the parent class CalendarViewCustom (similar to its existing methods) which can then be called on an instance of the class i.e.

public int setMonthDateColor(Date date, int color) {
    return mDelegate.getMonthDateColor(date, color);
}

All you need to do then is draw the listed colours on the canvas in the WeekView class method called drawWeekNumbersAndDates() for the specified dates using the existing for loop ( for (; i < nDays; i++) ) and iterate over the Map and change the paint colour for the date text i.e. mMonthNumDrawPaint.setColor().

Hope this points you in the right direction.

sreejith

Try this. Hope this helps

android:weekDayTextAppearance="@style/CalendarWeekDateText"


<style name="CalendarWeekDatText" parent="TextAppearance.AppCompat.Button">
    <item name="android:textColor">#000000</item>
</style>
android:theme="@style/testTheme"

Use this theme or a custom theme which has parent as this theme.

To make it white

To Choose other than white change the color use the following

android:textColorPrimary="@color/yourColor"

for other text colors use the following

android:weekDayTextAppearance="@style/weekDayTextAppearance"
    android:dateTextAppearance="@style/appTextAppearance"
    android:unfocusedMonthDateColor="@color/colorLoginBtn"
    android:selectedWeekBackgroundColor="@color/colorLoginBtn"
    android:weekSeparatorLineColor="@color/colorLoginBtn"
    android:focusedMonthDateColor="@color/colorLoginBtn"
    android:weekNumberColor="@color/colorLoginBtn"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!