EditText

2026-09-20Loading rating…

1. Feature Description

RemoteEditText is an editable component for receiving user text input, corresponding to ViewType.EDIT_TEXT. It supports hint text, font size, color, font style, alignment, keyboard input type, max length, automatic grouping, cursor positioning, character limits, multi/single line, and text-change listening. It fits forms, search boxes, numeric entry, and similar scenarios.

Create it via RemoteViewHelper.createEditText():

val input = helper.createEditText()

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

Input Properties

MethodParamsDescription
setTextStringText content
setTextSizeFloatFont size (rounded to sp internally)
setTextColorIntText color (ARGB Int)
setGravityGravityTypeAlignment: CENTER / START / END / LEFT / RIGHT / TOP / BOTTOM, etc.
setFontStyleFontStyleTypeFont style: NORMAL / BOLD / ITALIC / BOLD_ITALIC
setHintStringHint (placeholder) text
setHintByResIdIntSet hint via a resource ID; auto-switches with the server-side language
setHintTextColorIntHint text color (ARGB Int)
setInputTypeInputTypeKeyboard input type (see valid values below)
setMaxLengthIntMaximum number of input characters
setGroupingStringAuto grouping: inserts a space every group (e.g. "4" → every 4 digits)
setCursorPositionIntCursor position (0-based index)
setMaxLinesIntMax number of lines
setSingleLineBooleanWhether single line
setEllipsizeEllipsizeTypeEllipsis position: START / MIDDLE / END / MARQUEE
setVerticalScrollableBooleanWhether vertical scrolling is allowed (multi-line long text)

InputType valid values: TEXT / TEXT_MULTI_LINE / NUMBER / NUMBER_DECIMAL / NUMBER_SIGNED / PHONE / EMAIL_ADDRESS / PASSWORD / NUMBER_PASSWORD.

Events

MethodParamsDescription
setOnTextChangeListenerIRemoteViewTextWatcherText-change listener with beforeTextChanged / onTextChanged / afterTextChanged. Callbacks run on the Binder thread pool

3. Tips

  1. Colors must be ARGB Int. setTextColor / setHintTextColor / setBackground accept an Int color value (e.g. 0xFF1A8BFF.toInt() or Color.RED). Do not pass "#RRGGBB", "0xAARRGGBB", or R.color.xxx.
  2. setOnTextChangeListener callbacks run on the Binder thread pool, not the main thread. To update UI or touch main-thread-only objects inside the callback, switch back to the main thread first (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. Use setInputType(InputType.PASSWORD) for password input (use NUMBER_PASSWORD for numeric passwords); text is masked with dots.
  5. Use setMaxLength(n) to limit characters; use setGrouping("4") for auto grouping (inserts a separator space every 4 characters, ideal for card/serial numbers).
  6. Use setHintByResId(resId) instead of setHint(String) when the hint must follow language switching; the hint text refreshes automatically when the server-side language changes.

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 Input Styles (default / custom hint color / rounded background)

// Filled rounded background: black fill + centered blue text
val filled = helper.createEditText().apply {
    setWidth(RemoteView.MATCH_PARENT); setHeight(36)
    setText("Filled input")
    setTextColor(0xFF1A8BFF.toInt())
    setGravity(GravityType.CENTER)
    setBackgroundShape(
        ShapeDescriptor.Builder().fillColor(0x99000000.toInt()).cornerRadius(4f).build()
    )
}

// Outlined rounded background: 1dp grey stroke + centered white text
val outlined = helper.createEditText().apply {
    setWidth(RemoteView.MATCH_PARENT); setHeight(36)
    setText("Outlined input")
    setTextColor(0xFFFFFFFF.toInt())
    setGravity(GravityType.CENTER)
    setBackgroundShape(
        ShapeDescriptor.Builder().stroke(1, 0xFF888888.toInt()).cornerRadius(4f).build()
    )
}

// Default style: no fill / no stroke + centered white text
val plain = helper.createEditText().apply {
    setWidth(RemoteView.MATCH_PARENT); setHeight(36)
    setText("Default input")
    setTextColor(0xFFFFFFFF.toInt())
    setGravity(GravityType.CENTER)
}

// Custom hint colors: grey hint / red hint
val hintGrey = helper.createEditText().apply {
    setWidth(RemoteView.MATCH_PARENT); setHeight(36)
    setHint("Enter content")
    setHintTextColor(0x55FFFFFF.toInt())
    setGravity(GravityType.CENTER)
    setBackgroundShape(
        ShapeDescriptor.Builder().fillColor(0x99000000.toInt()).cornerRadius(4f).build()
    )
}
val hintRed = helper.createEditText().apply {
    setWidth(RemoteView.MATCH_PARENT); setHeight(36)
    setHint("Enter content")
    setHintTextColor(0x55D54941.toInt())
    setGravity(GravityType.CENTER)
    setBackgroundShape(
        ShapeDescriptor.Builder().fillColor(0x99000000.toInt()).cornerRadius(4f).build()
    )
}

02 Input Control (number keyboard / password / auto grouping / max length)

// Number keyboard: shows a numeric-only soft keyboard
val number = helper.createEditText().apply {
    setWidth(RemoteView.MATCH_PARENT); setHeight(36)
    setHint("Number mode")
    setInputType(InputType.NUMBER)
    setText("012345678910")
    setTextColor(0xFF1A8BFF.toInt())
    setGravity(GravityType.CENTER)
    setBackgroundShape(
        ShapeDescriptor.Builder().fillColor(0x99000000.toInt()).cornerRadius(4f).build()
    )
}

// Password: text masked with dots
val password = helper.createEditText().apply {
    setWidth(RemoteView.MATCH_PARENT); setHeight(36)
    setHint("Password mode")
    setInputType(InputType.PASSWORD)
    setText("012345678910")
    setTextColor(0xFF1A8BFF.toInt())
    setGravity(GravityType.CENTER)
    setBackgroundShape(
        ShapeDescriptor.Builder().fillColor(0x99000000.toInt()).cornerRadius(4f).build()
    )
}

// Auto grouping: inserts a space every 4 digits (card number)
val grouping = helper.createEditText().apply {
    setWidth(RemoteView.MATCH_PARENT); setHeight(36)
    setHint("Card number")
    setGrouping("4")
    setText("0000111122223333")
    setTextColor(0xFF1A8BFF.toInt())
    setGravity(GravityType.CENTER)
    setBackgroundShape(
        ShapeDescriptor.Builder().fillColor(0x99000000.toInt()).cornerRadius(4f).build()
    )
}

// Max length: up to 8 characters
val maxLength = helper.createEditText().apply {
    setWidth(RemoteView.MATCH_PARENT); setHeight(36)
    setHint("Up to 8 characters")
    setMaxLength(8)
    setText("Max 8 ch")
    setTextColor(0xFF1A8BFF.toInt())
    setGravity(GravityType.CENTER)
    setBackgroundShape(
        ShapeDescriptor.Builder().fillColor(0x99000000.toInt()).cornerRadius(4f).build()
    )
}

// Text-change listener (callbacks run on the Binder thread pool; switch to main thread to update UI)
number.setOnTextChangeListener(object : IRemoteViewTextWatcher {
    override fun beforeTextChanged(s: String, start: Int, count: Int, after: Int) {}
    override fun onTextChanged(s: String, start: Int, before: Int, count: Int) {
        Handler(Looper.getMainLooper()).post {
            // Safely update UI on the main thread
        }
    }
    override fun afterTextChanged(s: String) {}
})

For a full runnable example, see drawing/EditTextDrawer.ktopen in new window in the official Sample open-pilot-plugin-sample.

Last Updated: