/ Checkable

A checkable widget for Android. Based on the EventFilterView from the Google I/O 2018 app

A checkable widget for Android. Based on the EventFilterView from the Google I/O 2018 app

CheckableChipView

A checkable widget for Android. Based on the EventFilterView from the Google I/O 2018 app.

Requires Android minSdkVersion 21.

CheckableChipView

Setup

Make sure you have the jcenter repo in your project level build.gradle

allprojects {
    repositories {
        jcenter()
    }
}

Add the dependency to your lib/app build.gradle

dependencies {
    implementation 'com.github.okdroid:checkablechipview:1.0.1'
}

Usage

XML

Include the widget into your xml layout like this

<com.github.okdroid.checkablechipview.CheckableChipView
        android:id="@+id/chip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pie Cake" />

The following xml attributes are supported

Attribute Description
android:text The text to display
android:textColor The default text color
android:color The color of the indicator dot as well as the background color when the widget is checked
android:background The default background color
android:checked The checked state of the widget, either true or false
app:ccv_outlineColor The color of the outline
app:ccv_outlineCornerRadius The corner radius of the outline, in dp. Defaults to a pill shape if not set
app:ccv_outlineWidth The stroke width of the outline, in dp
app:ccv_checkedTextColor The text color when the widget is checked
app:ccv_foreground The foreground drawable to display

In code

The state of the widget can be observed like this

chip.onCheckedChangeListener = { view: CheckableChipView, isChecked: Boolean ->
    // do your logic here
}

To switch between checked/unchecked state programatically with animation, use the following method:

chip.setCheckedAnimated(checked = true) {
    // onAnimationEnd callback
}

Plus, there are following methods at your service for changing the state without animation:

if (!chip.isChecked) {
    chip.isChecked = true
}

chip.toggle() // toggles between states

GitHub