在没有onClickListener的情况下在日历视图中突出显示特定日期 [英] highlighting specific date in calendar view without onClickListener

查看:82
本文介绍了在没有onClickListener的情况下在日历视图中突出显示特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种好方法可以在Android的日历视图中突出显示特定日期/不同日期?谢谢!

Is there a good way to highlight a specific/different dates as I want on calendar view in android? Thanks!

推荐答案

private void setCustomResourceForDates() {

        Calendar cal = Calendar.getInstance();
        //highlighlighting the holidays in a month taking the static dates
        ArrayList<String> dates = new ArrayList<String>();
        dates.add("02-08-2015");
        dates.add("22-08-2015");
        dates.add("17-09-2015");
        dates.add("25-09-2015");
        dates.add("27-09-2015");
        dates.add("13-10-2015");
        dates.add("22-10-2015");
        SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy");
        Date date = new Date();
        for (int i = 1; i < dates.size(); i++) {
            inputString2 = dates.get(i);
            inputString1 = myFormat.format(date);

            try {
                //Converting String format to date format
                date1 = myFormat.parse(inputString1);
                date2 = myFormat.parse(inputString2);
                //Calculating number of days from two dates
                long diff = date2.getTime() - date1.getTime();
                long datee = diff / (1000 * 60 * 60 * 24);
                //Converting long type to int type
                day = (int) datee;
            } catch (ParseException e) {
                e.printStackTrace();
            }
            cal = Calendar.getInstance();
            cal.add(Calendar.DATE, day);
            holidayDay = cal.getTime();
            colors();

        }
    }

    public void colors() {
        if (caldroidFragment != null) {
            caldroidFragment.setBackgroundResourceForDate(R.color.green,
                    holidayDay);
            caldroidFragment.setTextColorForDate(R.color.white, holidayDay);
        }
    }
}

使用onCreate方法(在Caldroid日历中)调用setCustomResourceForDates();.

call setCustomResourceForDates(); on onCreate method (in Caldroid Calendar).

这篇关于在没有onClickListener的情况下在日历视图中突出显示特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆