【问题标题】:Can't highlight particular date in Calendarview in Android无法在 Android 的 Calendarview 中突出显示特定日期
【发布时间】:2015-09-16 15:19:50
【问题描述】:

我正在片段中使用 CalendarView。我已经向它添加了事件。我必须突出显示我添加事件的日期。无法在默认日历视图中获取任何用于突出显示特定日期的 api。

感谢任何帮助!

【问题讨论】:

标签: android calendarview


【解决方案1】:

私人无效 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();

        /*cal = Calendar.getInstance();
        cal.add(Calendar.DATE,0);
        minDay = cal.getTime();

        cal = Calendar.getInstance();
        cal.add(Calendar.DATE,0);
        maxDay = cal.getTime();

        caldroidFragment.setMinDate(minDay);
        caldroidFragment.setMaxDate(maxDay);*/


    }
}

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

在 onCreate() 中调用这个 setCustomResourceForDates() --(在 Caldroid 日历中)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-26
    • 2021-07-29
    • 2014-04-08
    相关资源
    最近更新 更多