androidx.compose.ui.window
Interfaces
DialogWindowProvider |
Provides the underlying window of a dialog. |
PopupPositionProvider |
Calculates the position of a Popup on screen. |
Classes
DialogProperties |
Properties used to customize the behavior of a Dialog. |
PopupProperties |
Properties used to customize the behavior of a Popup. |
Enums
SecureFlagPolicy |
Policy on setting WindowManager.LayoutParams.FLAG_SECURE on a window. |
Top-level functions summary
Unit |
Dialog(onDismissRequest: () -> Unit, properties: DialogProperties = DialogProperties(), content: () -> Unit) Opens a dialog with the given content. |
Unit |
Popup(alignment: Alignment = Alignment.TopStart, offset: IntOffset = IntOffset(0, 0), onDismissRequest: () -> Unit = null, properties: PopupProperties = PopupProperties(), content: () -> Unit) Opens a popup with the given content. |
Unit |
Popup(popupPositionProvider: PopupPositionProvider, onDismissRequest: () -> Unit = null, properties: PopupProperties = PopupProperties(), content: () -> Unit) Opens a popup with the given content. |
Boolean |
isPopupLayout(view: View, testTag: String? = null) Returns whether the given view is an underlying decor view of a popup. |
Top-level functions
Dialog
@Composable fun Dialog(
onDismissRequest: () -> Unit,
properties: DialogProperties = DialogProperties(),
content: () -> Unit
): Unit
Opens a dialog with the given content.
The dialog is visible as long as it is part of the composition hierarchy. In order to let the user dismiss the Dialog, the implementation of onDismissRequest should contain a way to remove to remove the dialog from the composition hierarchy.
Example usage:
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.background import androidx.compose.foundation.layout.size import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.window.Dialog val openDialog = remember { mutableStateOf(true) } val dialogWidth = 200.dp val dialogHeight = 50.dp if (openDialog.value) { Dialog(onDismissRequest = { openDialog.value = false }) { // Draw a rectangle shape with rounded corners inside the dialog Box(Modifier.size(dialogWidth, dialogHeight).background(Color.White)) } }
Parameters | |
---|---|
onDismissRequest: () -> Unit | Executes when the user tries to dismiss the dialog. |
properties: DialogProperties = DialogProperties() | DialogProperties for further customization of this dialog's behavior. |
content: () -> Unit | The content to be displayed inside the dialog. |
Popup
@Composable fun Popup(
alignment: Alignment = Alignment.TopStart,
offset: IntOffset = IntOffset(0, 0),
onDismissRequest: () -> Unit = null,
properties: PopupProperties = PopupProperties(),
content: () -> Unit
): Unit
Opens a popup with the given content.
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.
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.background import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.ui.window.Popup 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)) ) } }
Parameters | |
---|---|
alignment: Alignment = Alignment.TopStart | The alignment relative to the parent. |
offset: |