LayoutElementBuilders.FontStyle.Builder


public final class LayoutElementBuilders.FontStyle.Builder


Builder for FontStyle

Summary

Public constructors

Creates an instance of Builder.

Public methods

@NonNull LayoutElementBuilders.FontStyle

Builds an instance from accumulated values.

@NonNull LayoutElementBuilders.FontStyle.Builder

Sets the text color.

@NonNull LayoutElementBuilders.FontStyle.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setItalic(boolean italic)

Sets whether the text should be rendered in a italic typeface.

@NonNull LayoutElementBuilders.FontStyle.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setItalic(@NonNull TypeBuilders.BoolProp italic)

Sets whether the text should be rendered in a italic typeface.

@NonNull LayoutElementBuilders.FontStyle.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setLetterSpacing(@NonNull DimensionBuilders.EmProp letterSpacing)

Sets the text letter-spacing.

@NonNull LayoutElementBuilders.FontStyle.Builder

Sets the size of the font, in scaled pixels (sp).

@NonNull LayoutElementBuilders.FontStyle.Builder
@RequiresSchemaVersion(major = 1, minor = 300)
@ProtoLayoutExperimental
setSizes(
    @NonNull @IntRange(from = 1) @Dimension(unit = Dimension.SP) int[] sizes
)

Sets the available sizes of the font, in scaled pixels (sp).

@NonNull LayoutElementBuilders.FontStyle.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setUnderline(boolean underline)

Sets whether the text should be rendered with an underline.

@NonNull LayoutElementBuilders.FontStyle.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setUnderline(@NonNull TypeBuilders.BoolProp underline)

Sets whether the text should be rendered with an underline.

@NonNull LayoutElementBuilders.FontStyle.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
@ProtoLayoutExperimental
setVariant(int variant)

Sets the variant of a font.

@NonNull LayoutElementBuilders.FontStyle.Builder

Sets the variant of a font.

@NonNull LayoutElementBuilders.FontStyle.Builder
@RequiresSchemaVersion(major = 1, minor = 0)
setWeight(int weight)

Sets the weight of the font.

@NonNull LayoutElementBuilders.FontStyle.Builder

Sets the weight of the font.

Public constructors

Builder

Added in 1.0.0
public Builder()

Creates an instance of Builder.

Public methods

build

Added in 1.0.0
public @NonNull LayoutElementBuilders.FontStyle build()

Builds an instance from accumulated values.

setColor

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.FontStyle.Builder setColor(@NonNull ColorBuilders.ColorProp color)

Sets the text color. If not defined, defaults to white.

While this field 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).

setItalic

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.FontStyle.Builder setItalic(boolean italic)

Sets whether the text should be rendered in a italic typeface. If not specified, defaults to "false".

setItalic

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.FontStyle.Builder setItalic(@NonNull TypeBuilders.BoolProp italic)

Sets whether the text should be rendered in a italic typeface. If not specified, defaults to "false".

Note that this field only supports static values.

setLetterSpacing

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.FontStyle.Builder setLetterSpacing(@NonNull DimensionBuilders.EmProp letterSpacing)

Sets the text letter-spacing. Positive numbers increase the space between letters while negative numbers tighten the space. If not specified, defaults to 0.

setSize

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.FontStyle.Builder setSize(@NonNull DimensionBuilders.SpProp size)

Sets the size of the font, in scaled pixels (sp). If not specified, defaults to the size of the system's "body" font.

Any previously added values with this method or setSizes will be cleared.

setSizes

@RequiresSchemaVersion(major = 1, minor = 300)
@ProtoLayoutExperimental
public @NonNull LayoutElementBuilders.FontStyle.Builder setSizes(
    @NonNull @IntRange(from = 1) @Dimension(unit = Dimension.SP) int[] sizes
)

Sets the available sizes of the font, in scaled pixels (sp). If not specified, defaults to the size of the system's "body" font.

If more than one size is specified and this FontStyle is applied to a Text element with static text, the text size will be automatically picked from the provided sizes to try to perfectly fit within its parent bounds. In other words, the largest size from the specified preset sizes that can fit the most text within the parent bounds will be used.

The specified sizes don't have to be sorted, but they need to contain only positive values. The maximum number of sizes used is limited to 10.

Note that, if multiple sizes are set, the parent of the Text element this corresponds to shouldn't have its width and height set to wrapped, as it can lead to unexpected results.

If this FontStyle is set to any other element besides Text or that Text element has dynamic field, only the last added size will be used.

Any previously added values with this method or setSize will be cleared.

While this field is accessible from 1.0 as singular, it only accepts multiple values since version 1.3 and renderers supporting version 1.3 will use the multiple values to automatically scale text. Renderers who don't support this version will use the last size among multiple values.

Throws
java.lang.IllegalArgumentException

if the number of available sizes is larger than 10 or one of the sizes is not a positive value.

setUnderline

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.FontStyle.Builder setUnderline(boolean underline)

Sets whether the text should be rendered with an underline. If not specified, defaults to "false".

setUnderline

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.FontStyle.Builder setUnderline(@NonNull TypeBuilders.BoolProp underline)

Sets whether the text should be rendered with an underline. If not specified, defaults to "false".

Note that this field only supports static values.

setVariant

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
@ProtoLayoutExperimental
public @NonNull LayoutElementBuilders.FontStyle.Builder setVariant(int variant)

Sets the variant of a font. Some renderers may use different fonts for title and body text, which can be selected using this field. If not specified, defaults to "body".

setVariant

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
@ProtoLayoutExperimental
public @NonNull LayoutElementBuilders.FontStyle.Builder setVariant(@NonNull LayoutElementBuilders.FontVariantProp variant)

Sets the variant of a font. Some renderers may use different fonts for title and body text, which can be selected using this field. If not specified, defaults to "body".

setWeight

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.FontStyle.Builder setWeight(int weight)

Sets the weight of the font. If the provided value is not supported on a platform, the nearest supported value will be used. If not defined, or when set to an invalid value, defaults to "normal".

setWeight

Added in 1.0.0
@RequiresSchemaVersion(major = 1, minor = 0)
public @NonNull LayoutElementBuilders.FontStyle.Builder setWeight(@NonNull LayoutElementBuilders.FontWeightProp weight)

Sets the weight of the font. If the provided value is not supported on a platform, the nearest supported value will be used. If not defined, or when set to an invalid value, defaults to "normal".