Text
1. Feature Description
RemoteText is a component for displaying static text, corresponding to ViewType.TEXT_VIEW. It supports font size, color, font style (bold/italic), alignment, text decoration (underline/strikethrough), single-line truncation, multi-line ellipsis, scrollable long text, letter/line spacing, etc. It fits titles, descriptions, and status information.
Create it via RemoteViewHelper.createText():
val label = helper.createText()
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 |
Text Properties
| Method | Params | Description |
|---|---|---|
setText | String | Text content |
setTextSize | Float | Font size (rounded to sp internally) |
setTextColor | Int | Text color (ARGB Int) |
setFontStyle | FontStyleType | Font style: NORMAL / BOLD / ITALIC / BOLD_ITALIC |
setGravity | GravityType | Alignment: CENTER / START / END / LEFT / RIGHT / TOP / BOTTOM, etc. |
setTextDecoration | TextDecorationType | Decoration: NONE / UNDERLINE / STRIKE_THROUGH / UNDERLINE_AND_STRIKE_THROUGH |
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 (long text) |
setLetterSpacing | Float | Letter spacing |
setLineSpacing | extra: Float, multiplier: Float | Line spacing (extra + multiplier) |
3. Tips
- Colors must be ARGB Int.
setTextColor/setBackgroundaccept an Int color value (e.g.0xFF1890FF.toInt()orColor.RED); the underlyingupdateViewconverts it to a decimal string. Do not pass"#RRGGBB","0xAARRGGBB", orR.color.xxx. - 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. - Single-line truncation needs
setSingleLine(true)+setEllipsize(...). Setting onlysingleLinetruncates without an ellipsis; combine withEllipsizeType.ENDto show "…". - Scrollable long text needs
setVerticalScrollable(true)plus a boundedsetHeight, otherwise the text keeps expanding instead of scrolling. - When
setMaxLinesandsetSingleLine(true)are both set, single line takes precedence.
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 Component Types (basic / special text)
// Basic text: normal / underline / strikethrough / bold / colored
val normal = helper.createText().apply {
setText("Normal text"); setWidth(RemoteView.MATCH_PARENT); setTextSize(14f)
}
val underline = helper.createText().apply {
setText("Underlined text"); setWidth(RemoteView.MATCH_PARENT); setTextSize(14f)
setTextDecoration(TextDecorationType.UNDERLINE)
}
val strike = helper.createText().apply {
setText("Strikethrough text"); setWidth(RemoteView.MATCH_PARENT); setTextSize(14f)
setTextDecoration(TextDecorationType.STRIKE_THROUGH)
}
val bold = helper.createText().apply {
setText("Bold text"); setWidth(RemoteView.MATCH_PARENT); setTextSize(14f)
setFontStyle(FontStyleType.BOLD)
}
val colored = helper.createText().apply {
setText("Colored text"); setWidth(RemoteView.MATCH_PARENT); setTextSize(14f)
setTextColor(0xFF1890FF.toInt())
}
// Special types: single line / ellipsis / wrap / scrollable
val singleLine = helper.createText().apply {
setText("Single line text"); setWidth(RemoteView.MATCH_PARENT); setSingleLine(true)
}
val ellipsize = helper.createText().apply {
setText("Long text that is truncated and does not show all content,Long text that is truncated and does not show all content")
setWidth(RemoteView.MATCH_PARENT); setSingleLine(true); setEllipsize(EllipsizeType.END)
}
val wrap = helper.createText().apply {
setText("Long text that wraps to show all content,Long text that wraps to show all content,Long text that wraps to show all content")
setWidth(RemoteView.MATCH_PARENT); setMaxLines(3)
}
val scrollable = helper.createText().apply {
setText("Some text, long content, scrollable display")
setWidth(RemoteView.MATCH_PARENT); setHeight(56); setVerticalScrollable(true)
}
02 Component States (normal / greyed)
// Normal state
val normal = helper.createText().apply {
setText("Normal text"); setWidth(RemoteView.MATCH_PARENT); setTextSize(14f)
}
// Greyed state: reduced opacity + grey color
val disabled = helper.createText().apply {
setText("Disabled (greyed) text"); setWidth(RemoteView.MATCH_PARENT); setTextSize(14f)
setTextColor(0xFF888888.toInt())
setAlpha(0.6f)
}
03 Component Styles (font size / custom colors)
// Font size: L 12sp / M 11sp / S 9sp (with letter/line spacing)
val large = helper.createText().apply {
setText("L, 12sp"); setWidth(RemoteView.MATCH_PARENT)
setTextSize(12f); setLetterSpacing(0.01f)
}
val medium = helper.createText().apply {
setText("M, 11sp"); setWidth(RemoteView.MATCH_PARENT)
setTextSize(11f); setLetterSpacing(0.03f); setLineSpacing(1f, 1f)
}
val small = helper.createText().apply {
setText("S, 9sp"); setWidth(RemoteView.MATCH_PARENT)
setTextSize(9f); setLetterSpacing(0.05f); setLineSpacing(0f, 1.3f)
}
// Custom colors: blue / red / orange
val blue = helper.createText().apply { setText("Blue text"); setTextColor(0xFF1890FF.toInt()) }
val red = helper.createText().apply { setText("Red text"); setTextColor(0xFFE41F29.toInt()) }
val orange = helper.createText().apply { setText("Orange text"); setTextColor(0xFFFF9F0A.toInt()) }
For a full runnable example, see drawing/TextViewDrawer.kt in the official Sample
open-pilot-plugin-sample.