Class CardBuilder

  • CardBuilder is used to build Card objects.

  • You can add card actions and sections to a Card using the builder.

  • The build() method finalizes and validates the Card object.

  • Various methods allow setting the card's display style, footer, header, name, and peek card header.

CardBuilder

A builder for Card objects.

Methods

MethodReturn typeBrief description
addCardAction(cardAction) CardBuilder Adds a CardAction to this Card.
addSection(section) CardBuilder Adds a section to this card.
build() Card Builds the current card and validates it.
setDisplayStyle(displayStyle) CardBuilder Sets the display style for this card.
setFixedFooter(fixedFooter) CardBuilder Sets a fixed footer for this card.
setHeader(cardHeader) CardBuilder Sets the header for this card.
setName(name) CardBuilder Sets the name for this card.
setPeekCardHeader(peekCardHeader) CardBuilder Sets the peek card header.

Detailed documentation

addCardAction(cardAction)

Adds a CardAction to this Card.

Parameters

NameTypeDescription
cardActionCardAction The CardAction to use.

Return

CardBuilder — This object, for chaining.


addSection(section)

Adds a section to this card. You can't add more than 100 sections to a card.

Parameters

NameTypeDescription
sectionCardSection The CardSection to use.

Return

CardBuilder — This object, for chaining.


build()

Builds the current card and validates it.

Return

Card — A validated card.

Throws

Error — if the constructed card isn't valid.


setDisplayStyle(displayStyle)

Sets the display style for this card.

If the display style is set to DisplayStyle.REPLACE, the card is shown by replacing the view of top card in the card stack.

If the display style is set to DisplayStyle.PEEK, the header of the card appears at the bottom of the sidebar, partially covering the current top card of the stack. Clicking the header pops the card into the card stack. If the card has no header, a generated header is used instead.

DisplayStyle only works for card returned from contextual trigger function.

Parameters

NameTypeDescription
displayStyleDisplayStyle The DisplayStyle to set.

Return

CardBuilder — This object, for chaining.


setFixedFooter(fixedFooter)

Sets a fixed footer for this card.

Parameters

NameTypeDescription
fixedFooterFixedFooter The FixedFooter to use.

Return

CardBuilder — This object, for chaining.


setHeader(cardHeader)

Sets the header for this card.

Parameters

NameTypeDescription
cardHeaderCardHeader The CardHeader to use.

Return

CardBuilder — This object, for chaining.


setName(name)

Sets the name for this card. The name can be used for navigation.

Parameters

NameTypeDescription
nameStringThe name.

Return

CardBuilder — This object, for chaining.


setPeekCardHeader(peekCardHeader)

Sets the peek card header.

The peek card is set on the first card returned from a contextual trigger function. It is used as a descriptive placeholder widget so that users can navigate from a homepage stack to the contextual stack.

Parameters

NameTypeDescription
peekCardHeaderCardHeader The CardHeader to set.

Return

CardBuilder — This object, 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月02日 UTC.