Spinner

2026-09-20Loading rating…

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)

MethodParamsDescription
setWidthIntWidth (dp); special values RemoteView.MATCH_PARENT(-1) / WRAP_CONTENT(-2)
setHeightIntHeight (dp); same special values
setMinSizeminWidth: Int, minHeight: IntMinimum size (dp)
setPaddingleft, top, right, bottom: IntPadding (dp)
setVisibilityVisibilityTypeVisibility: VISIBLE / INVISIBLE / GONE
setAlphaFloatOpacity, 0.0 – 1.0
setEnabledBooleanWhether enabled

Background & Shape (inherited from RemoteViewProvider)

MethodParamsDescription
setBackgroundIntSolid background color (ARGB Int)
setBackgroundShapeShapeDescriptorBackground shape: fill / stroke / corner radius

Spinner Properties

MethodParamsDescription
setItemsList<String>Option text list
setItemsByResIdsList<Int>Set options from a list of R.string.xxx resource IDs; text refreshes automatically with the Pilot-side language
setSelectedIndexIntCurrent selected index (0-based)
setDropdownBackgroundColorIntDropdown popup background color (ARGB Int); affects only the popup list area, not the header
setDropdownTextColorIntOption text color in the dropdown popup (ARGB Int)
setSelectedTextColorIntSelected item text color (ARGB Int)
setSpinnerIconColorIntTrailing dropdown icon color (ARGB Int)
setGravityGravityTypeHeader text alignment: CENTER / START / END / LEFT / RIGHT, etc.

Events

MethodParamsDescription
setOnItemSelectedListenerIRemoteViewOnItemSelectedListenerItem-selected callback onItemSelected(index: Int, item: String), runs on the Binder thread pool

3. Tips

  1. Colors must be ARGB Int. setDropdownBackgroundColor / setDropdownTextColor / setSelectedTextColor / setSpinnerIconColor all accept an Int color value (e.g. 0xFF2696FF.toInt() or Color.WHITE). Do not pass "#RRGGBB", "0xAARRGGBB", or R.color.xxx.
  2. The selected callback runs on the Binder thread pool. The onItemSelected callback of setOnItemSelectedListener is 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 { ... }).
  3. Call syncToRemote() after changing a mounted component's properties. setXxx only updates the local cache; syncToRemote() batch-syncs to Pilot. If you configure properties before mounting, no extra call is needed.
  4. setSelectedIndex is 0-based and must fall within the range of the setItems list length; out-of-range values have no effect.
  5. Prefer setItemsByResIds for multi-language scenarios. Passing a list of R.string.xxx resource IDs lets option text refresh automatically when the Pilot-side language changes; strings passed to setItems are fixed and do not follow the language.
  6. 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.ktopen in new window in the official Sample open-pilot-plugin-sample.

Last Updated: