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.
An 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.
onDismissRequest
Executes when the user clicks outside of the popup.
properties
[PopupProperties] for further customization of this popup's behavior.
content
The content to be displayed inside the popup.
@ComposablefunPopup( popupPositionProvider: PopupPositionProvider, onDismissRequest:(()-> Unit)?, properties: PopupProperties, content:@Composable()-> Unit
)
Parameters
name
description
popupPositionProvider
Provides the screen position of the popup.
onDismissRequest
Executes when the user clicks outside of the popup.
properties
[PopupProperties] for further customization of this popup's behavior.
An 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.
onDismissRequest
Executes when the user clicks outside of the popup.
properties
[PopupProperties] for further customization of this popup's behavior.
An 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.
focusable
Indicates if the popup can grab the focus.
onDismissRequest
Executes when the user clicks outside of the popup.
onPreviewKeyEvent
This callback is invoked when the user interacts with the hardware keyboard. It gives ancestors of a focused component the chance to intercept a [KeyEvent]. Return true to stop propagation of this event. If you return false, the key event will be sent to this [onPreviewKeyEvent]'s child. If none of the children consume the event, it will be sent back up to the root using the onKeyEvent callback.
onKeyEvent
This callback is invoked when the user interacts with the hardware keyboard. While implementing this callback, return true to stop propagation of this event. If you return false, the key event will be sent to this [onKeyEvent]'s parent.
content
The content to be displayed inside the popup.
@Composable@Deprecated("Replaced by Popup with properties parameter",ReplaceWith("Popup(popupPositionProvider, onDismissRequest, "+"androidx.compose.ui.window.PopupProperties(focusable = focusable), "+"onPreviewKeyEvent, onKeyEvent, content)")funPopup( popupPositionProvider: PopupPositionProvider, onDismissRequest:(()-> Unit)?=null, onPreviewKeyEvent:((KeyEvent)-> Boolean)={false}, onKeyEvent:((KeyEvent)-> Boolean)={false}, focusable: Boolean =false, content:@Composable()-> Unit
)
Parameters
name
description
popupPositionProvider
Provides the screen position of the popup.
onDismissRequest
Executes when the user clicks outside of the popup.
focusable
Indicates if the popup can grab the focus.
onPreviewKeyEvent
This callback is invoked when the user interacts with the hardware keyboard. It gives ancestors of a focused component the chance to intercept a [KeyEvent]. Return true to stop propagation of this event. If you return false, the key event will be sent to this [onPreviewKeyEvent]'s child. If none of the children consume the event, it will be sent back up to the root using the onKeyEvent callback.
onKeyEvent
This callback is invoked when the user interacts with the hardware keyboard. While implementing this callback, return true to stop propagation of this event. If you return false, the key event will be sent to this [onKeyEvent]'s parent.
An 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.
onDismissRequest
Executes when the user clicks outside of the popup.
properties
[PopupProperties] for further customization of this popup's behavior.
content
The content to be displayed inside the popup.
@ComposablefunPopup( popupPositionProvider: PopupPositionProvider, onDismissRequest:(()-> Unit)?, properties: PopupProperties, content:@Composable()-> Unit
)
Parameters
name
description
popupPositionProvider
Provides the screen position of the popup.
onDismissRequest
Executes when the user clicks outside of the popup.
properties
[PopupProperties] for further customization of this popup's behavior.
An 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.
onDismissRequest
Executes when the user clicks outside of the popup.
properties
[PopupProperties] for further customization of this popup's behavior.
onPreviewKeyEvent
This callback is invoked when the user interacts with the hardware keyboard. It gives ancestors of a focused component the chance to intercept a [KeyEvent]. Return true to stop propagation of this event. If you return false, the key event will be sent to this [onPreviewKeyEvent]'s child. If none of the children consume the event, it will be sent back up to the root using the onKeyEvent callback.
onKeyEvent
This callback is invoked when the user interacts with the hardware keyboard. While implementing this callback, return true to stop propagation of this event. If you return false, the key event will be sent to this [onKeyEvent]'s parent.
Executes when the user clicks outside of the popup.
properties
[PopupProperties] for further customization of this popup's behavior.
onPreviewKeyEvent
This callback is invoked when the user interacts with the hardware keyboard. It gives ancestors of a focused component the chance to intercept a [KeyEvent]. Return true to stop propagation of this event. If you return false, the key event will be sent to this [onPreviewKeyEvent]'s child. If none of the children consume the event, it will be sent back up to the root using the onKeyEvent callback.
onKeyEvent
This callback is invoked when the user interacts with the hardware keyboard. While implementing this callback, return true to stop propagation of this event. If you return false, the key event will be sent to this [onKeyEvent]'s parent.
content
The content to be displayed inside the popup.
Code Example
PopupSample
@Composable@SampledfunPopupSample(){ 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 popupBox( Modifier
.size(popupWidth, popupHeight).background(Color.White,RoundedCornerShape(cornerSize)))}}}