CheckBox
1. Feature Description
RemoteCheckBox is a checkbox component with a text label, corresponding to ViewType.CHECK_BOX. It supports default checked state, checkbox tint, text, font size, font style, alignment, and a checked-change listener. It fits multi-select lists, agreement checks, toggle-style options, and similar scenarios.
Create it via RemoteViewHelper.createCheckBox():
val check = helper.createCheckBox()
2. Common Properties
The following properties are set via the corresponding setXxx() methods. Unless noted otherwise, if the component is already mounted, call syncToRemote() after changing a property to make it take effect on Pilot.
Size & Layout (inherited from RemoteViewProvider)
| Method | Params | Description |
|---|---|---|
setWidth | Int | Width (dp); special values RemoteView.MATCH_PARENT(-1) / WRAP_CONTENT(-2) |
setHeight | Int | Height (dp); same special values |
setMinSize | minWidth: Int, minHeight: Int | Minimum size (dp) |
setPadding | left, top, right, bottom: Int | Padding (dp) |
setVisibility | VisibilityType | Visibility: VISIBLE / INVISIBLE / GONE |
setAlpha | Float | Opacity, 0.0 – 1.0 |
setEnabled | Boolean | Whether enabled |
Background & Shape (inherited from RemoteViewProvider)
| Method | Params | Description |
|---|---|---|
setBackground | Int | Solid background color (ARGB Int) |
setBackgroundShape | ShapeDescriptor | Background shape: fill / stroke / corner radius |
CheckBox Properties
| Method | Params | Description |
|---|---|---|
setChecked | Boolean | Whether checked |
setCheckBoxTint | Int | Checkbox tint (ARGB Int) |
setText | String | Text label content |
setTextSize | Float | Font size (rounded to sp internally) |
setTextColor | Int | Text color (ARGB Int) |
setGravity | GravityType | Alignment: CENTER / START / END / LEFT / RIGHT / TOP / BOTTOM, etc. |
setFontStyle | FontStyleType | Font style: NORMAL / BOLD / ITALIC / BOLD_ITALIC |
Events
| Method | Params | Description |
|---|---|---|
setOnCheckChangeListener | IRemoteViewOnCheckedChangeListener | Checked-change listener: onCheckedChanged(view, isChecked). Callbacks run on the Binder thread pool |
3. Tips
- Colors must be ARGB Int.
setCheckBoxTint/setTextColoraccept an Int color value (e.g.0xFF1A8BFF.toInt()orColor.RED). Do not pass"#RRGGBB","0xAARRGGBB", orR.color.xxx. setOnCheckChangeListenercallbacks run on the Binder thread pool, not the main thread. To update UI inside the callback, switch back to the main thread first (e.g.Handler(Looper.getMainLooper()).post { ... }).- Call
syncToRemote()after changing a mounted component's properties.setXxxonly updates the local cache;syncToRemote()batch-syncs to Pilot. - The disabled state needs
setEnabled(false)combined withsetAlpha(...).setEnabled(false)alone only blocks interaction; combine it with reduced opacity for a visually greyed effect. setCheckBoxTintonly affects the tint of the box; the label color is controlled separately bysetTextColor.
4. Sample Code
In each group below, the code sample is on the left and the corresponding Pilot-side rendered preview is on the right.
01 CheckBox (unchecked / checked / blue / red / disabled)
// Unchecked
val unchecked = helper.createCheckBox().apply {
setText("Unchecked"); setHeight(30); setChecked(false)
}
// Checked
val checked = helper.createCheckBox().apply {
setText("Checked"); setHeight(30); setChecked(true)
}
// Blue tint
val blue = helper.createCheckBox().apply {
setText("Blue"); setHeight(30); setChecked(true)
setCheckBoxTint(0xFF1A8BFF.toInt())
}
// Red tint
val red = helper.createCheckBox().apply {
setText("Red"); setHeight(30); setChecked(true)
setCheckBoxTint(0xFFE41F29.toInt())
}
// Disabled: create first, then reduce opacity
val disabled = helper.createCheckBox().apply {
setText("Disabled"); setHeight(30); setChecked(true)
setEnabled(false)
setAlpha(0.6f)
}
// Checked-change listener (callbacks run on the Binder thread pool; switch to main thread to update UI)
checked.setOnCheckChangeListener(object : IRemoteViewOnCheckedChangeListener {
override fun onCheckedChanged(view: RemoteView, isChecked: Boolean) {
Handler(Looper.getMainLooper()).post {
// Safely update UI on the main thread
}
}
})
For a full runnable example, see drawing/CheckBoxDrawer.kt in the official Sample
open-pilot-plugin-sample.