Class SurfaceText
A static text node. The text may embed ${key} placeholders that the platform renderer
substitutes from the state map of the current timeline entry or live-activity update, so
frequently changing values do not require re-publishing the whole descriptor:
new SurfaceText("${status}").setFontSize(13).setColor(SurfaceColor.SECONDARY_LABEL)
For values the OS should animate on its own clock (countdowns, elapsed time) use
SurfaceDynamicText instead.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetColor()Returns the text color, or null for the platform default.intReturns the font size in dips, 0 for the platform default.Returns the font weight, or null for the platform default.intReturns the maximum line count, 0 for unlimited.getText()Returns the text, potentially containing${key}placeholders.Assigns a tap action to this node.Assigns a tap action with parameters to this node.setAlignment(SurfaceAlignment alignment) Sets this node's alignment within its parent.setBackground(SurfaceColor background) Sets the background color of this node.setColor(SurfaceColor color) Sets the text color.setCornerRadius(int radius) Sets the corner radius applied to the node's background.setFontSize(int fontSize) Sets the font size.setFontWeight(SurfaceFontWeight fontWeight) Sets the font weight.setMaxLines(int maxLines) Limits the number of rendered lines.setPadding(int all) Sets the same padding on all four sides.setPadding(int top, int right, int bottom, int left) Sets the padding of each side individually.setSize(int widthDips, int heightDips) Sets a fixed size for this node.setWeight(int weight) Sets the flexible-space weight of this node within a row or column.Methods inherited from class SurfaceNode
getActionId, getActionParams, getAlignment, getBackground, getCornerRadius, getHeightDips, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getWeight, getWidthDips
-
Constructor Details
-
SurfaceText
Creates a text node.
Parameters
text: literal text, optionally embedding${key}state placeholders
-
-
Method Details
-
setFontSize
Sets the font size.
Parameters
fontSize: the size in dips
Returns
this text node, for chaining
-
setFontWeight
Sets the font weight.
Parameters
fontWeight: the weight
Returns
this text node, for chaining
-
setColor
Sets the text color.
Parameters
color: the color
Returns
this text node, for chaining
-
setMaxLines
Limits the number of rendered lines.
Parameters
maxLines: maximum line count, 0 for unlimited
Returns
this text node, for chaining
-
getText
Returns the text, potentially containing${key}placeholders. -
getFontSize
public int getFontSize()Returns the font size in dips, 0 for the platform default. -
getFontWeight
Returns the font weight, or null for the platform default. -
getColor
Returns the text color, or null for the platform default. -
getMaxLines
public int getMaxLines()Returns the maximum line count, 0 for unlimited. -
setPadding
Description copied from class:SurfaceNodeSets the same padding on all four sides.
Parameters
all: padding in dips
Returns
this node, for chaining
- Overrides:
setPaddingin classSurfaceNode
-
setPadding
Description copied from class:SurfaceNodeSets the padding of each side individually.
Parameters
top: top padding in dipsright: right padding in dipsbottom: bottom padding in dipsleft: left padding in dips
Returns
this node, for chaining
- Overrides:
setPaddingin classSurfaceNode
-
setBackground
Description copied from class:SurfaceNodeSets the background color of this node.
Parameters
color: the background color
Returns
this node, for chaining
- Overrides:
setBackgroundin classSurfaceNode
-
setCornerRadius
Description copied from class:SurfaceNodeSets the corner radius applied to the node's background. May render square on Android versions below 12.
Parameters
radius: the corner radius in dips
Returns
this node, for chaining
- Overrides:
setCornerRadiusin classSurfaceNode
-
setAlignment
Description copied from class:SurfaceNodeSets this node's alignment within its parent. In a
SurfaceBoxall nine positions apply; in rows and columns only the cross-axis component is used.Parameters
alignment: the alignment
Returns
this node, for chaining
- Overrides:
setAlignmentin classSurfaceNode
-
setWeight
Description copied from class:SurfaceNodeSets the flexible-space weight of this node within a row or column. Nodes with a weight share the leftover space of the parent proportionally; a weight of 0 (the default) sizes the node to its natural size.
Parameters
weight: the relative weight, 0 for natural sizing
Returns
this node, for chaining
- Overrides:
setWeightin classSurfaceNode
-
setSize
Description copied from class:SurfaceNodeSets a fixed size for this node. A value of 0 (the default) keeps the natural size of the respective axis.
Parameters
widthDips: fixed width in dips, 0 for natural widthheightDips: fixed height in dips, 0 for natural height
Returns
this node, for chaining
- Overrides:
setSizein classSurfaceNode
-
setAction
Description copied from class:SurfaceNodeAssigns a tap action to this node. Tapping the node opens (or foregrounds) the app and delivers the action id to the handler registered with
Surfaces.setActionHandler(...). Note that small iOS home-screen widgets only honor the action of the root node.Parameters
actionId: the app-defined action identifier
Returns
this node, for chaining
- Overrides:
setActionin classSurfaceNode
-
setAction
Description copied from class:SurfaceNodeAssigns a tap action with parameters to this node. The parameter map may contain
String,NumberandBooleanvalues and is delivered verbatim with theSurfaceActionEvent.Parameters
actionId: the app-defined action identifierparams: parameters delivered with the action, may be null
Returns
this node, for chaining
- Overrides:
setActionin classSurfaceNode
-