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

androidx.compose.ui.window

Interfaces

DialogProperties

Common interface for dialog properties.

DialogWindowProvider

Provides the underlying window of a dialog.

PopupPositionProvider

Calculates the position of a Popup on screen.

PopupProperties

Common interface for popup properties.

Classes

AndroidDialogProperties

Android specific properties to configure a dialog.

AndroidPopupProperties

Android specific properties to configure a popup.

Enums

SecureFlagPolicy

Policy on setting WindowManager.LayoutParams.FLAG_SECURE on a window.

Top-level functions summary

Unit
Dialog(onDismissRequest: () -> Unit, properties: DialogProperties? = null, content: () -> 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, properties: PopupProperties? = null, content: () -> Unit)

Opens a popup with the given content.

Unit
Popup(popupPositionProvider: PopupPositionProvider, isFocusable: Boolean = false, onDismissRequest: () -> Unit = null, properties: PopupProperties? = null, 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? = null,
    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.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).background(Color.White))
    }
}
Parameters
onDismissRequest: () -> Unit Executes when the user tries to dismiss the Dialog.
properties: DialogProperties? = null Typically platform specific properties to further configure the dialog.
content: () -> 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,
    properties: PopupProperties? = null,
    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.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)
                .background(Color.White, RoundedCornerShape(cornerSize))
        )
    }
}
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 user clicks outside of the popup.
properties: PopupProperties? = null Typically platform specific properties to further configure the popup.
content: () -> Unit The content to be displayed inside the popup.
@Composable fun Popup(
    popupPositionProvider: PopupPositionProvider,
    isFocusable: Boolean = false,
    onDismissRequest: () -> Unit = null,
    properties: PopupProperties? = null,
    content: () -> Unit
): Unit

Opens a popup with the given content.

The popup is positioned based on the coordinates return from popupPositionProvider.

Parameters
popupPositionProvider: PopupPositionProvider The position provider to be used to determine popup's position.
isFocusable: Boolean = false Indicates if the popup can grab the focus.
onDismissRequest: () -> Unit = null Executes when the user clicks outside of the popup.
properties: PopupProperties? = null Typically platform specific properties to further configure the popup.
content: () -> Unit The content to be displayed inside the popup.

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.