首页 > 解决方案 > 我无法在 android 的材质日历中添加更多图标

问题描述

我想制作类似这张图片我正在研究android材料日历我正在制作一个怀孕日历,如果我将在接下来的几天点击一天选择,那么在里面添加自动图标是我的代码:

   calendarView.setOnDayClickListener(new OnDayClickListener() {
        @Override
        public void onDayClick(EventDay eventDay) {

            Calendar clickedDayCalendar = eventDay.getCalendar();
            /*      clickedDayCalendar.set( clickedDayCalendar.get(Calendar.DAY_OF_MONTH + 4) ,  clickedDayCalendar.get(Calendar.MONTH) , clickedDayCalendar.get(Calendar.YEAR));*/
            events.add(new EventDay(clickedDayCalendar, R.drawable.sample_icon_2));

            ArrayList<String> eventDays = new ArrayList<String>();


            calendarView.setEvents(events);



        /*    alert_diaog_picker(eventDay.getCalendar().getTime().toString());*/


         //   Calendar clickedDayCalendar = eventDay.getCalendar();
         /*   Toast.makeText(getContext(), "Selected Date:\n" + "Day = " + clickedDayCalendar.get(Calendar.DAY_OF_MONTH) +
                    "\n" + "Month = " + clickedDayCalendar.get(Calendar.MONTH) + "\n" + "Year = " + clickedDayCalendar.get(Calendar.YEAR), Toast.LENGTH_LONG).show();*/
        }
    });



    return view;
}

这是我的xml代码:

<com.applandeo.materialcalendarview.CalendarView
    android:id="@+id/calendarView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    app:abbreviationsBarColor="#303F9F"
    app:abbreviationsLabelsColor="@android:color/white"
    app:daysLabelsColor="@android:color/white"
    app:headerColor="#1A237E"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:pagesColor="#3F51B5"
    app:eventsEnabled="false"
    app:selectionColor="@android:color/white"
    app:selectionLabelColor="#3F51B5"
    app:anotherMonthsDaysLabelsColor="#3F51B5"
    app:todayLabelColor="#AEEA00"
    app:type="many_days_picker" />

<Button
    android:id="@+id/getDateButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Get date"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/calendarView" />

implementation 'com.applandeo:material-calendar-view:1.6.0'

现在它就像我单击日期时一样工作,它仅包含该日期的图标,但我想在接下来的四天再添加一个图标,请帮助我提前谢谢我感谢每一个答案

标签: androiddatepickercalendarcalendarview

解决方案


推荐阅读