Read this in other languages: English, 中文.
A custom clock view with a circular slider.
- Android 4.0 Jelly Bean(API level 16) or higher.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.a1573595:ClockSlider:v1.1.0'
}
Define ClockSlider on your xml.
<com.a1573595.clockslider.ClockSlider
android:id="@+id/clockSlider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cc_endHour="7"
app:cc_endIconResource="@drawable/oval_white"
app:cc_fillColor="?attr/colorPrimary"
app:cc_metricMode="clock"
app:cc_startHour="10"
app:cc_startIconResource="@drawable/oval_white"
app:cc_tickTextColor="?android:attr/textColorPrimary" />
Set listener.
binding.clockSlider.setOnTimeChangedListener(object : ClockSlider.OnTimeChangedListener {
override fun onStartChanged(hour: Int, minute: Int) {
...
}
override fun onEndChanged(hour: Int, minute: Int) {
...
}
})
Attribute | Type | Default | Description |
---|---|---|---|
cc_borderWidth | dimension | 72f | border width |
cc_metricTextSize | dimension | 130f | metric text size |
cc_borderColor | color | #CCCCCC | border color |
cc_fillColor | color | #FFFF00 | border fill color |
cc_tickTextColor | color | #000000 | tick text color |
cc_startIconResource | reference | android.R.drawable.btn_star_big_on | start icon resource |
cc_endIconResource | reference | android.R.drawable.btn_star_big_off | end icon resource |
cc_isStartEnabled | boolean | true | start icon enabled |
cc_isEndEnabled | boolean | true | end icon enabled |
cc_is24HR | boolean | false | 12HR or 24HR |
cc_startHour | float | 0f | start hour |
cc_endHour | float | 0f | end hour |
cc_metricMode | enum | counter | metric text mode |