Calendar view (CalendarView)
Common Properties:
Android:selectedweekbackgroundcolor (Sets the background color of the selected week)
Android:showweeknumber (set whether to show the week)
Android:unfocusedmonthdatecolor (Sets the color of date text for months without focus)
Android:weekdaytextappearance (set Text style for the day of the week)
Android:weeknumbercolor (Sets the color of the week number displayed)
Android:weekseparatorlinecolor (Sets the color of the week split line)
Monitoring method: Setondatchangelistener
Listener: Calendarview.ondatechangelistener
Below we look directly at the code:
1.Activity
//Calendar View Public classCalendarviewactivityextendsActivity {Privatecontext Context; PrivateCalendarView CalendarView; protected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.calendar_view); Context= This; CalendarView=(CalendarView) Findviewbyid (R.ID.CALENDARVIEWID); Calendarview.setondatechangelistener (NewCalendarview.ondatechangelistener () { Public voidOnselecteddaychange (CalendarView view,intYearintmonth,intdayofmonth) {String content= year+ "-" + (month+1) + "-" +DayOfMonth; Toast.maketext (Context,"You have chosen: \ n" +content, Toast.length_short). Show (); } }); } }
2.xml Layout file
<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" Match_parent " android:layout_height=" Match_parent " android:padding= "5DP" ><!--Calendar View- <calendarview android:id= "@+id/ Calendarviewid " android:layout_width=" Match_parent " android:layout_height=" Match _parent "/></relativelayout>
3. Effect Display Chart
Calendar view (CalendarView)