Google is committed to advancing racial equity for Black communities. See how.

androidx.compose.ui.window

Interfaces

DialogWindowProvider

Provides the underlying window of a dialog.

PopupPositionProvider

Calculates the position of a Popup on screen.

Top-level functions summary

actual Unit
Dialog(onDismissRequest: () -> Unit, children: () -> Unit)

Opens a dialog with the given content.

Unit
Popup(alignment: Alignment = Alignment.TopStart, offset: IntOffset = IntOffset(0, 0), isFocusable: Boolean = false, onDismissRequest: () -> Unit = null, children: () -> Unit)

Opens a popup with the given content.

Unit
Popup(popupPositionProvider: PopupPositionProvider, isFocusable: Boolean = false, onDismissRequest: () -> Unit = null, children: () -> Unit)

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 actual fun Dialog(
    onDismissRequest: () -> Unit,
    children: () -> 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.Box
import androidx.compose.foundation.layout.preferredSize
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.preferredSize(dialogWidth, dialogHeight), backgroundColor = Color.White)
    }
}
Parameters
onDismissRequest: () -> Unit Executes when the user tries to dismiss the Dialog.
children: () -> Unit The content to be displayed inside the dialog.
@Composable fun Popup(
    alignment: Alignment = Alignment.TopStart,
    offset: IntOffset = IntOffset(0, 0),
    isFocusable: Boolean = false,
    onDismissRequest: () -> Unit = null,
    children: () -> 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.Box
import androidx.compose.foundation.layout.preferredSize
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.preferredSize(popupWidth, popupHeight),
            shape = RoundedCornerShape(cornerSize),
            backgroundColor = Color.White
        )
    }
}
Parameters
alignment: Alignment = Alignment.TopStart The alignment relative to the parent.
offset: IntOffset = IntOffset(0, 0) 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.
isFocusable: Boolean = false Indicates if the popup can grab the focus.
onDismissRequest: () -> Unit = null Executes when the popup tries to dismiss itself. This happens when the popup is focusable and the user clicks outside.
children: () -> Unit The content to be displayed inside the popup.
@Composable fun Popup(
    popupPositionProvider: PopupPositionProvider,
    isFocusable: Boolean = false,
    onDismissRequest: () -> Unit = null,
    children: () -> Unit
): Unit

isPopupLayout

@TestOnly fun isPopupLayout(
    view: View,
    testTag: String? = null
): Boolean

Returns whether the given view is an underlying decor view of a popup. If the given testTag is supplied it also verifies that the popup has such tag assigned.

Parameters
view: View View to verify.
testTag: String? = null If provided, tests that the given tag in defined on the popup.