Class TextStyleBuilder

  • TextStyleBuilder is used to create text styles.

  • It provides methods to set properties like bold, italic, underline, strikethrough, font family, font size, and foreground color.

  • The build() method creates the final TextStyle object from the builder.

  • Most methods return the TextStyleBuilder itself, allowing for method chaining.

TextStyleBuilder

A builder for text styles.

Methods

MethodReturn typeBrief description
build() TextStyle Creates a text style from this builder.
setBold(bold) TextStyleBuilder Sets whether or not the text is bold.
setFontFamily(fontFamily) TextStyleBuilder Sets the text font family, such as "Arial".
setFontSize(fontSize) TextStyleBuilder Sets the text font size in points.
setForegroundColor(cssString) TextStyleBuilder Sets the text font color.
setForegroundColorObject(color) TextStyleBuilder Sets the text font color.
setItalic(italic) TextStyleBuilder Sets whether or not the text is italic.
setStrikethrough(strikethrough) TextStyleBuilder Sets whether or not the text has strikethrough.
setUnderline(underline) TextStyleBuilder Sets whether or not the text is underlined.

Detailed documentation

build()

Creates a text style from this builder.

Return

TextStyle — A text style created from this builder.


setBold(bold)

Sets whether or not the text is bold.

Parameters

NameTypeDescription
boldBooleanWhether or not the text is bold.

Return

TextStyleBuilder — The builder for chaining.


setFontFamily(fontFamily)

Sets the text font family, such as "Arial".

Parameters

NameTypeDescription
fontFamilyStringThe desired font family.

Return

TextStyleBuilder — The builder for chaining.


setFontSize(fontSize)

Sets the text font size in points.

Parameters

NameTypeDescription
fontSizeIntegerThe desired font size.

Return

TextStyleBuilder — The builder for chaining.


setForegroundColor(cssString)

Sets the text font color.

Parameters

NameTypeDescription
cssStringStringThe desired font color in CSS notation (such as '#ffffff' or 'white').

Return

TextStyleBuilder — The builder for chaining.


setForegroundColorObject(color)

Sets the text font color.

Parameters

NameTypeDescription
colorColor The desired font color.

Return

TextStyleBuilder — The builder for chaining.


setItalic(italic)

Sets whether or not the text is italic.

Parameters

NameTypeDescription
italicBooleanWhether or not the text is italic.

Return

TextStyleBuilder — The builder for chaining.


setStrikethrough(strikethrough)

Sets whether or not the text has strikethrough.

Parameters

NameTypeDescription
strikethroughBooleanWhether or not the text has strikethrough.

Return

TextStyleBuilder — The builder for chaining.


setUnderline(underline)

Sets whether or not the text is underlined.

Parameters

NameTypeDescription
underlineBooleanWhether or not the text is underlined.

Return

TextStyleBuilder — The builder for chaining.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024年12月03日 UTC.