This is a migrated thread and some comments may be shown as answers.

Cell Customization

1 Answer 65 Views
Calendar - Xamarin.Android
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 05 Mar 2015, 08:12 PM
Is there a way to add a custom image to the background of an individual cell?  I was able to do this in iOS fairly easily by setting a custom delegate and overriding ViewForCellOfKind.

1 Answer, 1 is accepted

Sort by
0
Antony Jekov
Telerik team
answered on 10 Mar 2015, 01:04 PM
Hello Jeff,

Thank you for contacting the Android team!

We don't support custom picture backgrounds by design, but we have a bitmap element in the cells, which can be modified to fill the cell thus become the background. This would be an example code:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 
    final RadCalendarView calendarView = new RadCalendarView(this);
    calendarView.setAdapter(new Adapter(calendarView));
    calendarView.getAdapter().setStyle(CalendarStyles.materialLight(this));
 
    final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_pic);
    calendarView.setCustomizationRule(new Procedure<CalendarCell>() {
        Calendar calendar = Calendar.getInstance();
        @Override
        public void apply(CalendarCell argument) {
            if (argument.getCellType() == CalendarCellType.Date) {
                calendar.setTimeInMillis(argument.getDate());
                if (calendar.get(Calendar.DATE) == 5) {
                    argument.setBitmap(bitmap);
                } else {
                    argument.setBitmap(null);
                }
            }
        }
    });
 
    setContentView(calendarView);
}
 
class Adapter extends CalendarAdapter {
 
    public Adapter(RadCalendarView owner) {
        super(owner);
    }
 
    @Override
    protected CalendarDayCell generateCalendarDayCell() {
        return new Cell(this.owner);
    }
 
    class Cell extends CalendarDayCell {
 
        public Cell(RadCalendarView owner) {
            super(owner);
 
            setBitmapPosition(CalendarElement.TOP | CalendarElement.LEFT);
        }
 
        @Override
        protected void onArrange() {
            super.onArrange();
            if (getBitmap() != null) {
                this.setBitmap(Bitmap.createBitmap(getBitmap(), 0, 0, getWidth(), getHeight()));
            }
        }
    }
}
Please let me know if this is what you meant and if it suits your needs.

Thank you for your time and all best!

Regards,
Antony Jekov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Calendar - Xamarin.Android
Asked by
Jeff
Top achievements
Rank 1
Answers by
Antony Jekov
Telerik team
Share this question
or