Text.Builder
public final class Text.Builder
Builder class for Text.
Summary
Public constructors |
|---|
|
Creates a builder for a |
Builder(Creates a builder for a |
Public methods |
|
|---|---|
@NonNull Text |
build()Constructs and returns |
@NonNull Text.Builder |
setColor(@NonNull ColorBuilders.ColorProp color)Sets the color for the |
@NonNull Text.Builder |
setItalic(boolean italic)Sets the text to be italic. |
@NonNull Text.Builder |
setMaxLines(@IntRange(from = 1) int maxLines)Sets the maximum lines of text. |
@NonNull Text.Builder |
setModifiers(@NonNull ModifiersBuilders.Modifiers modifiers)Sets the modifiers of text. |
@NonNull Text.Builder |
setMultilineAlignment(int multilineAlignment)Sets the multiline alignment for text within bounds of the Text element. |
@NonNull Text.Builder |
setOverflow(int overflow)Sets the overflow for text. |
@NonNull Text.Builder |
setScalable(boolean isScalable)Sets whether the text size will change if user has changed the default font size. |
@NonNull Text.Builder |
setTypography(int typography)Sets the typography for the |
@NonNull Text.Builder |
setUnderline(boolean underline)Sets the text to be underlined. |
@NonNull Text.Builder |
setWeight(int weight)Sets the weight of the font. |
Public constructors
Builder
public Builder(@NonNull Context context, @NonNull String text)
Creates a builder for a Text component with static text.
Builder
public Builder(
@NonNull Context context,
@NonNull TypeBuilders.StringProp text,
@NonNull TypeBuilders.StringLayoutConstraint stringLayoutConstraint
)
Creates a builder for a Text.
While this component is statically accessible from 1.0, it's only bindable since version 1.2 and renderers supporting version 1.2 will use the dynamic value (if set).
| Parameters | |
|---|---|
@NonNull Context context |
The application's context. |
@NonNull TypeBuilders.StringProp text |
The text content for this component. |
@NonNull TypeBuilders.StringLayoutConstraint stringLayoutConstraint |
Layout constraints used to correctly measure Text view size and align text when |
Public methods
build
public @NonNull Text build()
Constructs and returns Text with the provided content and look.
setColor
public @NonNull Text.Builder setColor(@NonNull ColorBuilders.ColorProp color)
Sets the color for the Text. If not set, onPrimary color from the DEFAULT will be used.
setItalic
public @NonNull Text.Builder setItalic(boolean italic)
Sets the text to be italic. If not set, false will be used.
setMaxLines
public @NonNull Text.Builder setMaxLines(@IntRange(from = 1) int maxLines)
Sets the maximum lines of text. If not set, 1 will be used.
setModifiers
public @NonNull Text.Builder setModifiers(@NonNull ModifiersBuilders.Modifiers modifiers)
Sets the modifiers of text.
setMultilineAlignment
public @NonNull Text.Builder setMultilineAlignment(int multilineAlignment)
Sets the multiline alignment for text within bounds of the Text element. Note that this option has no effect for single line of text, and for that, alignment on the outer container should be used. If not set, TEXT_ALIGN_CENTER will be used.
setOverflow
public @NonNull Text.Builder setOverflow(int overflow)
Sets the overflow for text. If not set, TEXT_OVERFLOW_ELLIPSIZE_END will be used.
setScalable
public @NonNull Text.Builder setScalable(boolean isScalable)
Sets whether the text size will change if user has changed the default font size. If not set, true will be used.
setTypography
public @NonNull Text.Builder setTypography(int typography)
Sets the typography for the Text. If not set, TYPOGRAPHY_DISPLAY1 will be used.
setUnderline
public @NonNull Text.Builder setUnderline(boolean underline)
Sets the text to be underlined. If not set, false will be used.
setWeight
public @NonNull Text.Builder setWeight(int weight)
Sets the weight of the font. If not set, default weight for the chosen Typography will be used.