Android Question Dialog DateTemplate

Guenter Becker

Active Member
Licensed User
Hi,
I need to know how to color the background of a special day in a month in the DateTemplate. For example to highlight weekend or holidays.

Can anyone help me with a B4A snipped.

Thank you and Happy X-mas and successfull New Year.
 

Guenter Becker

Active Member
Licensed User
Hi,
I need to know how to color the background of a special day in a month in the DateTemplate. For example to highlight weekend or holidays.

Can anyone help me with a B4A snipped.

Thank you and Happy X-mas and successfull New Year.
Thank you for your quick response.
I will try this. Anway is there no solution to direct adress the day objects of the DateTemplate like it is possible with the labels.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
The DateTemplate draws the days (box and text) with B4XCanvas.
So as it stands the template does not have a method to make custom colored days.

However, you can unzip the xui views library and use Notepad++ to look at the DateTemplate code.
Take a look at the DrawDays sub.
B4X:
Private Sub DrawDays
    lblMonth.Text = MonthsNames.Get(month - 1)
    lblYear.Text = year
    SetYearsButtonState
    cvs.ClearRect(cvs.TargetRect)
    cvsBackground.ClearRect(cvsBackground.TargetRect)
    Dim firstDayOfMonth As Long = DateUtils.setDate(year, month, 1) - 1
    dayOfWeekOffset = (7 + DateTime.GetDayOfWeek(firstDayOfMonth) - FirstDay) Mod 7
    daysInMonth = DateUtils.NumberOfDaysInMonth(month, year)
    If year = selectedYear And month = selectedMonth Then
        'draw the selected box
        DrawBox(cvs, SelectedColor, (selectedDay - 1 + dayOfWeekOffset) Mod 7, _
            (selectedDay - 1 + dayOfWeekOffset) / 7)
    End If
    Dim daysFont As B4XFont = xui.CreateDefaultBoldFont(14)
    For day = 1 To daysInMonth
        Dim row As Int = (day - 1 + dayOfWeekOffset) / 7
        cvs.DrawText(day, (((dayOfWeekOffset + day - 1) Mod 7) + 0.5) * boxW, _
            (row + 0.5)* boxH + vCorrection, daysFont, DaysInMonthColor , "CENTER")
    Next
    cvsBackground.Invalidate
    cvs.Invalidate
End Sub

You'll see that the sub draws a different colored box for the currently selected date (followed by drawing the text over it.
You could make your own version of the dateTemplate.bas module by adding a few lines to the DrawDays sub.
(for eaxmple if a day is saturday or sunday draw a different colored box).
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Hi William,
this is a good Idea. On this base I modified and extend the DateTemplate and just published the result to the audiance.
Post
Thank you for helping.

Whish you all happy X-Mas and successfull new Year.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…