I created a Custom Calendar Library because often the design of CalendarView from Google is less attractive and does not fit the design pattern of the application I will create. In this Library you can set the appearance of the Custom Calendar Library starting from the locale, color, and shape of the button and is only available on the Android platform. Here are the steps to implement this library:
Step one add it in your root build.gradle at the end of repositories 1
2
3
4
5
6
7
dependencyResolutionManagement {
repositoriesMode.set (RepositoriesMode.FAIL_ON_PROJECT_REPOS )
repositories {
mavenCentral()
maven { url = uri("https://www.jitpack.io" ) }
}
}
Step two Add the dependency 1
2
3
dependencies {
implementation("com.github.JOOctp:Custom-Calendar:1.0.3" )
}
Set your locale using xml or programmatically 1
2
3
4
5
< com.jop .calendar .CalendarView
android:id= "@+id/calendar"
android:layout_width= "match_parent"
android:layout_height= "wrap_content"
app:locale= "id-ID" />
1
2
3
binding.apply {
calendar.setLocale (Locale("id" , "ID" ))
}
You can customize the appearance of the buttons, from the background, stroke, icon color, and button shape using xml or programmatically. 1
2
3
4
5
6
7
8
9
< com.jop .calendar .CalendarView
android:id= "@+id/calendar"
android:layout_width= "match_parent"
android:layout_height= "wrap_content"
app:locale= "id-ID"
app:buttonStrokeColor= "@color/green"
app:buttonBackgroundColor= "@color/greenAccent"
app:buttonIconColor= "@color/green"
app:isCircleButton= "false" />
1
2
3
4
5
6
binding.apply {
calendar.setButtonStrokeColor (ColorStateList.valueOf (resources.getColor (R.color .green )))
calendar.setButtonBackgroundColor (ColorStateList.valueOf (resources.getColor (R.color .greenAccent )))
calendar.setButtonIconColor (ColorStateList.valueOf (resources.getColor (R.color .green )))
calendar.setIsCircleButton (false )
}
You can set the weekend color using xml or programmatically. 1
2
3
4
5
6
< com.jop .calendar .CalendarView
android:id= "@+id/calendar"
android:layout_width= "match_parent"
android:layout_height= "wrap_content"
app:locale= "id-ID"
app:textWeekEndColor= "@color/grey" />
Callback function when clicked on selected date 1
2
3
4
5
6
7
binding.apply {
calendar.setCalenderViewListener (object : CalendarView.CalendarViewListener {
override fun onSelectedDate (date: Date) {
TODO("Not yet implemented" )
}
})
}