EditText
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)
| 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 |
Input Properties
| Method | Params | Description |
|---|---|---|
setText | String | Text 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 |
setHint | String | Hint (placeholder) text |
setHintByResId | Int | Set hint via a resource ID; auto-switches with the server-side language |
setHintTextColor | Int | Hint text color (ARGB Int) |
setInputType | InputType | Keyboard input type (see valid values below) |
setMaxLength | Int | Maximum number of input characters |
setGrouping | String | Auto grouping: inserts a space every group (e.g. "4" → every 4 digits) |
setCursorPosition | Int | Cursor position (0-based index) |
setMaxLines | Int | Max number of lines |
setSingleLine | Boolean | Whether single line |
setEllipsize | EllipsizeType | Ellipsis position: START / MIDDLE / END / MARQUEE |
setVerticalScrollable | Boolean | Whether 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
| Method | Params | Description |
|---|---|---|
setOnTextChangeListener | IRemoteViewTextWatcher | Text-change listener with beforeTextChanged / onTextChanged / afterTextChanged. Callbacks run on the Binder thread pool |
3. Tips
- Colors must be ARGB Int.
setTextColor/setHintTextColor/setBackgroundaccept an Int color value (e.g.0xFF1A8BFF.toInt()orColor.RED). Do not pass"#RRGGBB","0xAARRGGBB", orR.color.xxx. setOnTextChangeListenercallbacks 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 { ... }).- 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. - Use
setInputType(InputType.PASSWORD)for password input (useNUMBER_PASSWORDfor numeric passwords); text is masked with dots. - Use
setMaxLength(n)to limit characters; usesetGrouping("4")for auto grouping (inserts a separator space every 4 characters, ideal for card/serial numbers). - Use
setHintByResId(resId)instead ofsetHint(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.kt in the official Sample
open-pilot-plugin-sample.