我正在使用npanigrahy:自定义日历视图来显示我的自定义日历,但我的问题是如何在日历中创建的事件上添加循环项目符号,这对我来说很难实现,因为我第一次开发此项目我希望任何人都可以推荐或教我的模块
答案 0 :(得分:7)
这是使用this库的最佳方式。我有这样的意思:
calendarView.addDecorators(new CurrentDayDecorator(this));
和这里的CurrentDayDecatator类:
package com.calendar.util;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import com.calendar.MainActivity;
import com.calendar.R;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
/**
* Created by Navruz on 17.06.2016.
*/
public class CurrentDayDecorator implements DayViewDecorator {
private Drawable drawable;
CalendarDay currentDay = CalendarDay.from(new Date());
public CurrentDayDecorator(Activity context) {
drawable = ContextCompat.getDrawable(context, R.drawable.first_day_month);
}
@Override
public boolean shouldDecorate(CalendarDay day) {
return day.equals(currentDay);
}
@Override
public void decorate(DayViewFacade view) {
view.setSelectionDrawable(drawable);
}
}
这里是circele drawable,名为first_day_month
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_shortAnimTime">
<item android:state_checked="true"
android:drawable="@drawable/selected_bg_color" />
<item android:state_pressed="true"
android:drawable="@drawable/selected_bg_color" />
<item android:drawable="@drawable/red_circle" />
red_circle:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="2"
android:useLevel="false" >
<solid android:color="@android:color/transparent" />
<stroke
android:width="2dp"
android:color="@color/selected_color" />
selected_bg_color:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="@color/selected_color"/>
<size
android:width="120dp"
android:height="120dp"/>