学习 square 日历框架 android-times-square

来源:互联网 发布:mac 印象笔记插件下载 编辑:程序博客网 时间:2024/05/23 05:09



查看github注意到android-times-square

将项目开发中的心得写出来与大家分享。

一 实现CellView 选择器

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_selected="true">        <shape android:shape="oval" >            <solid android:color="#f4d05d" />            <stroke android:width="10dp" android:color="@android:color/white" />            <size android:width="30dp" android:height="30dp" />        </shape>    </item>    <item android:state_pressed="true">        <shape android:shape="oval" android:useLevel="false">            <solid android:color="#f4d05d" />            <stroke android:width="10dp" android:color="@android:color/white" />            <size android:width="30dp" android:height="30dp" />        </shape>    </item>    <item>        <color android:color="@color/white" />    </item></selector>


二 实现日程红点提醒

class SampleDecorator implements CalendarCellDecorator {        List<String> times;        public SampleDecorator(List<String> times) {            this.times = times;        }        @Override        public void decorate(CalendarCellView cellView, Date date) {//            if(!cellView.isCurrentMonth())//                return;            //设置文字            String temp = simpleDateFormat.format(date);            if (times.contains(temp)) {                String time = Integer.toString(date.getDate());                SpannableString string = new SpannableString(time + "     ");                Drawable drawable = getResources().getDrawable(R.mipmap.red_dian);                drawable.setBounds(0, 0, 10, 10);                ImageSpan imageSpan = new ImageSpan(drawable);                string.setSpan(imageSpan, time.length(), string.length(),                        Spanned.SPAN_INCLUSIVE_EXCLUSIVE);                cellView.getDayOfMonthTextView().setText(string);            }        }    }

项目完整代码