Build apps faster with our new App builder! Check it out →

Popup

Common
Android

Component in Compose Ui

Opens a popup with the given content.

A popup is a floating container that appears on top of the current activity. It is especially useful for non-modal UI surfaces that remain hidden until they are needed, for example floating menus like Cut/Copy/Paste.

The popup is positioned relative to its parent, using the [alignment] and [offset]. The popup is visible as long as it is part of the composition hierarchy.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.ui:ui:1.8.0-alpha04")
}

Overloads

@Composable
fun Popup(
    alignment: Alignment = Alignment.TopStart,
    offset: IntOffset = IntOffset(0, 0),
    onDismissRequest: (() -> Unit)? = null,
    properties: PopupProperties = PopupProperties(),
    content: @Composable () -> Unit
)

Parameters

namedescription
alignmentThe alignment relative to the parent.
offsetAn offset from the original aligned position of the popup. Offset respects the Ltr/Rtl context, thus in Ltr it will be added to the original aligned position and in Rtl it will be subtracted from it.
onDismissRequestExecutes when the user clicks outside of the popup.
properties[PopupProperties] for further customization of this popup's behavior.
contentThe content to be displayed inside the popup.
@Composable
fun Popup(
    popupPositionProvider: PopupPositionProvider,
    onDismissRequest: (() -> Unit)? = null,
    properties: PopupProperties = PopupProperties(),
    content: @Composable () -> Unit
)

Parameters

namedescription
popupPositionProviderProvides the screen position of the popup.
onDismissRequestExecutes when the user clicks outside of the popup.
properties[PopupProperties] for further customization of this popup's behavior.
contentThe content to be displayed inside the popup.
@Composable
fun Popup(
    alignment: Alignment,
    offset: IntOffset,
    onDismissRequest: (() -> Unit)?,
    properties: PopupProperties,
    content: @Composable () -> Unit
)

Parameters

namedescription
alignmentThe alignment relative to the parent.
offsetAn offset from the original aligned position of the popup. Offset respects the Ltr/Rtl context, thus in Ltr it will be added to the original aligned position and in Rtl it will be subtracted from it.
onDismissRequestExecutes when the user clicks outside of the popup.
properties[PopupProperties] for further customization of this popup's behavior.
contentThe content to be displayed inside the popup.
@Composable
fun Popup(
    popupPositionProvider: PopupPositionProvider,
    onDismissRequest: (() -> Unit)?,
    properties: PopupProperties,
    content: @Composable () -> Unit
)

Parameters

namedescription
popupPositionProviderProvides the screen position of the popup.
onDismissRequestExecutes when the user clicks outside of the popup.
properties[PopupProperties] for further customization of this popup's behavior.
contentThe content to be displayed inside the popup.

Code Example

PopupSample

@Composable
fun PopupSample() {
    Box {
        val popupWidth = 200.dp
        val popupHeight = 50.dp
        val cornerSize = 16.dp

        Popup(alignment = Alignment.Center) {
            // Draw a rectangle shape with rounded corners inside the popup
            Box(
                Modifier.size(popupWidth, popupHeight)
                    .background(Color.White, RoundedCornerShape(cornerSize))
            )
        }
    }
}
by @alexstyl