Spinner
1. Feature Description
RemoteSpinner is a dropdown component for single selection from a set of options, corresponding to ViewType.SPINNER. It supports setting the option list, specifying the default selected item, customizing the dropdown popup background / option text color / selected text color / trailing icon color, and listening to item-selected events. It fits switchable enum-style configurations (such as flight mode, gear level, etc.).
Create it via RemoteViewHelper.createSpinner():
val spinner = helper.createSpinner()
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 |
Spinner Properties
| Method | Params | Description |
|---|---|---|
setItems | List<String> | Option text list |
setItemsByResIds | List<Int> | Set options from a list of R.string.xxx resource IDs; text refreshes automatically with the Pilot-side language |
setSelectedIndex | Int | Current selected index (0-based) |
setDropdownBackgroundColor | Int | Dropdown popup background color (ARGB Int); affects only the popup list area, not the header |
setDropdownTextColor | Int | Option text color in the dropdown popup (ARGB Int) |
setSelectedTextColor | Int | Selected item text color (ARGB Int) |
setSpinnerIconColor | Int | Trailing dropdown icon color (ARGB Int) |
setGravity | GravityType | Header text alignment: CENTER / START / END / LEFT / RIGHT, etc. |
Events
| Method | Params | Description |
|---|---|---|
setOnItemSelectedListener | IRemoteViewOnItemSelectedListener | Item-selected callback onItemSelected(index: Int, item: String), runs on the Binder thread pool |
3. Tips
- Colors must be ARGB Int.
setDropdownBackgroundColor/setDropdownTextColor/setSelectedTextColor/setSpinnerIconColorall accept an Int color value (e.g.0xFF2696FF.toInt()orColor.WHITE). Do not pass"#RRGGBB","0xAARRGGBB", orR.color.xxx. - The selected callback runs on the Binder thread pool. The
onItemSelectedcallback ofsetOnItemSelectedListeneris not on the main thread. To update the UI or touch main-thread-only APIs, switch back to the main thread yourself (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. If you configure properties before mounting, no extra call is needed. setSelectedIndexis 0-based and must fall within the range of thesetItemslist length; out-of-range values have no effect.- Prefer
setItemsByResIdsfor multi-language scenarios. Passing a list ofR.string.xxxresource IDs lets option text refresh automatically when the Pilot-side language changes; strings passed tosetItemsare fixed and do not follow the language. - The Pilot side does not yet support applying font size / text color / font style to the Spinner header, so the SDK does not expose those setters. To highlight the selected item's color, use
setSelectedTextColor.
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 Dropdown (default selection / specified selection / custom popup colors)
val items = listOf("Land", "RTH", "Hover")
// Default selects index 0, and listens for selection (callback on Binder thread, switch to main thread for UI)
val defaultSpinner = helper.createSpinner().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(40)
setBackgroundShape(
ShapeDescriptor.Builder()
.stroke(1, 0xFFFFFFFF.toInt()).fillColor(0xFF000000.toInt()).cornerRadius(4f).build()
)
setItems(items)
setSelectedIndex(0)
setGravity(GravityType.CENTER)
setSelectedTextColor(0xFF2696FF.toInt())
setDropdownTextColor(0x88E7E7E7.toInt())
setSpinnerIconColor(0x88E7E7E7.toInt())
setOnItemSelectedListener { index, item ->
Handler(Looper.getMainLooper()).post {
// Update the UI after switching to the main thread
}
}
}
// Specify default selection at index 2 (0-based, i.e. "Hover")
val indexSpinner = helper.createSpinner().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(40)
setBackgroundShape(
ShapeDescriptor.Builder()
.stroke(1, 0xFFFFFFFF.toInt()).fillColor(0xFF000000.toInt()).cornerRadius(4f).build()
)
setItems(items)
setSelectedIndex(2)
setGravity(GravityType.CENTER)
setSelectedTextColor(0xFF2696FF.toInt())
setDropdownTextColor(0x88E7E7E7.toInt())
setSpinnerIconColor(0x88E7E7E7.toInt())
}
// Custom dropdown background & text colors (grey background, white selected text, white icon)
val customSpinner = helper.createSpinner().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(40)
setBackgroundShape(
ShapeDescriptor.Builder()
.stroke(1, 0xFF000000.toInt()).fillColor(0xFF373A41.toInt()).cornerRadius(4f).build()
)
setItems(items)
setSelectedIndex(0)
setGravity(GravityType.CENTER)
setSelectedTextColor(0xFFFFFFFF.toInt())
setDropdownBackgroundColor(0xFF373A41.toInt())
setDropdownTextColor(0x88E7E7E7.toInt())
setSpinnerIconColor(0xFFFFFFFF.toInt())
}
For a full runnable example, see drawing/SpinnerDrawer.kt in the official Sample
open-pilot-plugin-sample.