我有一个日期列表,我想在 calendarview 上将其涂成红色。
我能怎么做 ?
我的活动..
public class Calendario extends Activity {
RelativeLayout rl;
final Calendar calendar = Calendar.getInstance();
CalendarView cal;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calendar);
rl = (RelativeLayout) findViewById(R.id.rl);
cal = new CalendarView(Calendario.this);
rl.addView(cal);
cal.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month,
int dayOfMonth) {
// TODO Auto-generated method stub
}
});
}
}
我必须添加什么代码才能为日期着色?
您最好的选择可能是创建自己的日历视图类。根据找到的源码自定义日历视图here.
然后,您可以向 LegacyCalendarViewDelegate 类添加一个类似于 setFocusedMonthDateColor() 方法的额外方法,以迭代周并在 WeekView 类中设置日期和颜色(可能值得将这些键/值日期/颜色存储为 Map 集合实例) WeekView 类中的变量)。例如
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);
}
}
}
然后需要通过向父类 CalendarViewCustom 添加另一个方法(类似于其现有方法)来公开上述方法,然后可以在该类的实例上调用该方法,即
public int setMonthDateColor(Date date, int color) {
return mDelegate.getMonthDateColor(date, color);
}
然后,您需要做的就是使用现有的 for 循环 ( for (; i
希望这能为您指明正确的方向。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)