Text

2026-09-20Loading rating…

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)

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

Text Properties

MethodParamsDescription
setTextStringText content
setTextSizeFloatFont size (rounded to sp internally)
setTextColorIntText color (ARGB Int)
setFontStyleFontStyleTypeFont style: NORMAL / BOLD / ITALIC / BOLD_ITALIC
setGravityGravityTypeAlignment: CENTER / START / END / LEFT / RIGHT / TOP / BOTTOM, etc.
setTextDecorationTextDecorationTypeDecoration: NONE / UNDERLINE / STRIKE_THROUGH / UNDERLINE_AND_STRIKE_THROUGH
setMaxLinesIntMax number of lines
setSingleLineBooleanWhether single line
setEllipsizeEllipsizeTypeEllipsis position: START / MIDDLE / END / MARQUEE
setVerticalScrollableBooleanWhether vertical scrolling is allowed (long text)
setLetterSpacingFloatLetter spacing
setLineSpacingextra: Float, multiplier: FloatLine spacing (extra + multiplier)

3. Tips

  1. Colors must be ARGB Int. setTextColor / setBackground accept an Int color value (e.g. 0xFF1890FF.toInt() or Color.RED); the underlying updateView converts it to a decimal string. Do not pass "#RRGGBB", "0xAARRGGBB", or R.color.xxx.
  2. 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.
  3. Single-line truncation needs setSingleLine(true) + setEllipsize(...). Setting only singleLine truncates without an ellipsis; combine with EllipsizeType.END to show "…".
  4. Scrollable long text needs setVerticalScrollable(true) plus a bounded setHeight, otherwise the text keeps expanding instead of scrolling.
  5. When setMaxLines and setSingleLine(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.ktopen in new window in the official Sample open-pilot-plugin-sample.

Last Updated: