androidx.compose.material3

TooltipBox

Composable function

A tooltip explains an element, usually an icon button. It shows on hover with a mouse, or on long press on touch screens.

Wrap the element in a TooltipBox, and put a PlainTooltip or RichTooltip in its tooltip slot.

A plain tooltip on an icon button
A plain tooltip on an icon button
Box(Modifier.size(200.dp, 120.dp), contentAlignment = Alignment.BottomCenter) {
    TooltipBox(
        positionProvider = TooltipDefaults.rememberTooltipPositionProvider(TooltipAnchorPosition.Above),
        tooltip = { PlainTooltip { Text("Add to favorites") } },
        // Visible right away only for this picture. Normally: rememberTooltipState()
        state = rememberTooltipState(initialIsVisible = true, isPersistent = true),
    ) {
        IconButton(onClick = {}) { Icon(Icons.Filled.Favorite, "Favorite") }
    }
}

A rich tooltip has a title, more text and an action. Use it to explain a feature.

A rich tooltip with title and action
A rich tooltip with title and action
Box(Modifier.size(320.dp, 240.dp), contentAlignment = Alignment.BottomCenter) {
    TooltipBox(
        positionProvider = TooltipDefaults.rememberTooltipPositionProvider(TooltipAnchorPosition.Above),
        tooltip = {
            RichTooltip(
                title = { Text("Smart search") },
                action = { TextButton(onClick = {}) { Text("Learn more") } },
            ) {
                Text("Search finds text inside your photos too.")
            }
        },
        state = rememberTooltipState(initialIsVisible = true, isPersistent = true),
    ) {
        IconButton(onClick = {}) { Icon(Icons.Filled.Info, "About search") }
    }
}

Parameters

@Composable
fun TooltipBox(
    positionProvider: PopupPositionProvider,
    tooltip: @Composable TooltipScope.() -> Unit,
    state: TooltipState,
    modifier: Modifier = Modifier,
    onDismissRequest: (() -> Unit)? = null,
    focusable: Boolean = false,
    enableUserInput: Boolean = true,
    hasAction: Boolean = false,
    content: @Composable () -> Unit,
)

positionProvider: PopupPositionProviderRequired

tooltip: @Composable TooltipScope.() -> UnitRequired

The tooltip. A PlainTooltip or a RichTooltip.

state: TooltipStateRequired

Whether the tooltip is visible. Create it with rememberTooltipState(). Set isPersistent = true for rich tooltips with an action, so they stay until dismissed.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. See the Modifier guide.

onDismissRequest: (() -> Unit)?OptionalSince 1.9

Default: null

Called when the user taps outside a visible tooltip.

focusable: BooleanOptional

Default: false

Set to true if the tooltip has buttons the user should reach with the keyboard.

enableUserInput: BooleanOptional

Default: true

Set to false to show the tooltip only from code, not on hover or long press.

hasAction: BooleanOptionalSince 1.9

Default: false

Set to true when the tooltip has an action. It then stays visible longer.

content: @Composable () -> UnitRequired

The element the tooltip explains. Usually an IconButton.

Parts