PopupProperties


Properties used to customize the behavior of a Popup.

Summary

Public constructors

PopupProperties(
    focusable: Boolean,
    dismissOnBackPress: Boolean,
    dismissOnClickOutside: Boolean,
    clippingEnabled: Boolean,
    usePlatformDefaultWidth: Boolean
)
Cmn
android
PopupProperties(
    focusable: Boolean,
    dismissOnBackPress: Boolean,
    dismissOnClickOutside: Boolean,
    securePolicy: SecureFlagPolicy,
    excludeFromSystemGesture: Boolean,
    clippingEnabled: Boolean
)
android
PopupProperties(
    flags: Int,
    inheritSecurePolicy: Boolean,
    dismissOnBackPress: Boolean,
    dismissOnClickOutside: Boolean,
    excludeFromSystemGesture: Boolean,
    usePlatformDefaultWidth: Boolean,
    windowType: Int,
    windowToken: IBinder?
)
android
PopupProperties(
    focusable: Boolean,
    dismissOnBackPress: Boolean,
    dismissOnClickOutside: Boolean,
    securePolicy: SecureFlagPolicy,
    excludeFromSystemGesture: Boolean,
    clippingEnabled: Boolean,
    usePlatformDefaultWidth: Boolean,
    windowType: Int,
    windowToken: IBinder?
)

Constructs a PopupProperties with the given behaviors.

android

Public functions

open operator Boolean
equals(other: Any?)
android
open Int
android

Public properties

Boolean

Whether to allow the popup window to extend beyond the bounds of the screen.

Cmn
android
Boolean

Whether the popup can be dismissed by pressing the back or escape buttons on Android or the escape key on desktop.

Cmn
android
Boolean

Whether the popup can be dismissed by clicking outside the popup's bounds.

Cmn
android
Boolean

A flag to check whether to set the systemGestureExclusionRects.

android
Boolean

Whether the popup is focusable.

Cmn
android
SecureFlagPolicy

Policy for how WindowManager.LayoutParams.FLAG_SECURE is set on the popup's window.

android
Boolean

Whether the width of the popup's content should be limited to the platform default, which is smaller than the screen width.

Cmn
android
IBinder?

An optional android.os.IBinder to be used as the window token for the popup window.

android
Int

An optional WindowManager.LayoutParams.type for the popup window.

android

Public constructors

PopupProperties

PopupProperties(
    focusable: Boolean = false,
    dismissOnBackPress: Boolean = true,
    dismissOnClickOutside: Boolean = true,
    clippingEnabled: Boolean = true,
    usePlatformDefaultWidth: Boolean = false
)

PopupProperties

PopupProperties(
    focusable: Boolean = false,
    dismissOnBackPress: Boolean = true,
    dismissOnClickOutside: Boolean = true,
    securePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit,
    excludeFromSystemGesture: Boolean = true,
    clippingEnabled: Boolean = true
)

PopupProperties

PopupProperties(
    flags: Int,
    inheritSecurePolicy: Boolean = true,
    dismissOnBackPress: Boolean = true,
    dismissOnClickOutside: Boolean = true,
    excludeFromSystemGesture: Boolean = true,
    usePlatformDefaultWidth: Boolean = false,
    windowType: Int = WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL,
    windowToken: IBinder? = null
)

PopupProperties

PopupProperties(
    focusable: Boolean = false,
    dismissOnBackPress: Boolean = true,
    dismissOnClickOutside: Boolean = true,
    securePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit,
    excludeFromSystemGesture: Boolean = true,
    clippingEnabled: Boolean = true,
    usePlatformDefaultWidth: Boolean = false,
    windowType: Int = WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL,
    windowToken: IBinder? = null
)

Constructs a PopupProperties with the given behaviors. This constructor is to support multiplatform and maintain backwards compatibility. Consider the overload that takes a flags parameter if more precise control over the popup flags is desired.

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupProperties

// In a real Service scenario, appWindowToken would be received via IPC
// from the main application process. This sample simulates having the token.
val appWindowToken: IBinder? = null // Provided via IPC

var showPopup by remember { mutableStateOf(false) }

Button(onClick = { showPopup = true }) { Text("Show Popup From Service") }

if (showPopup) {
    Popup(
        onDismissRequest = { showPopup = false },
        properties =
            PopupProperties(
                // Pass the application's window token
                windowToken = appWindowToken
            ),
    ) {
        Box(Modifier.size(200.dp, 100.dp).background(Color.Blue.copy(alpha = 0.8f))) {
            Text("Popup Content (Service)", color = Color.White)
        }
    }
}
Parameters
focusable: Boolean = false

Whether the popup is focusable. When true, the popup will receive IME events and key presses, such as when the back button is pressed.

dismissOnBackPress: Boolean = true

Whether the popup can be dismissed by pressing the back or escape buttons. If true, pressing the back or escape buttons will call onDismissRequest. Note that focusable must be set to true in order to receive key events such as the back button. If the popup is not focusable, then this property does nothing.

dismissOnClickOutside: Boolean = true

Whether the popup can be dismissed by clicking outside the popup's bounds. If true, clicking outside the popup will call onDismissRequest.

securePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit

Policy for setting WindowManager.LayoutParams.FLAG_SECURE on the popup's window.

excludeFromSystemGesture: Boolean = true

A flag to check whether to set the systemGestureExclusionRects. The default is true.

clippingEnabled: Boolean = true

Whether to allow the popup window to extend beyond the bounds of the screen. By default the window is clipped to the screen boundaries. Setting this to false will allow windows to be accurately positioned. The default value is true.

usePlatformDefaultWidth: Boolean = false

Whether the width of the popup's content should be limited to the platform default, which is smaller than the screen width.

windowType: Int = WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL

An optional WindowManager.LayoutParams.type for the popup window. Defaults to WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL. Overriding this allows you to change the layer or behavior of the popup. For example, setting it to WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY can be used to display a popup on top of all other applications (which requires the android.Manifest.permission.SYSTEM_ALERT_WINDOW permission). Note: If you are displaying a popup from a non-Activity context (such as an android.app.Service) but still want it to be anchored to an existing application window, you should leave this as the default sub-panel type and instead provide the windowToken of the target application window.

windowToken: IBinder? = null

An optional android.os.IBinder to be used as the window token for the popup window. In most cases, this can be left null, and the popup will use the token from the hosting Compose view (android.view.View.getApplicationWindowToken). However, this parameter is essential for cross-process scenarios. For instance, if a Service running in a different process needs to display a popup anchored to a window in the main application process, the main application's window token must be provided here. The provided token must be a validandroid.os.IBinder from an existing window and must have the necessary permissions to add sub-windows of the specifiedwindowType. Providing an invalid, stale, or permission-denied token will typically result in an android.view.WindowManager.BadTokenException when the popup attempts to show.

Example usage:

Public functions

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

Public properties

clippingEnabled

val clippingEnabledBoolean

Whether to allow the popup window to extend beyond the bounds of the screen. By default the window is clipped to the screen boundaries. Setting this to false will allow windows to be accurately positioned. The default value is true.

dismissOnBackPress

val dismissOnBackPressBoolean

Whether the popup can be dismissed by pressing the back or escape buttons on Android or the escape key on desktop. If true, pressing the back button will call onDismissRequest. Note that focusable must be set to true in order to receive key events such as the back button - if the popup is not focusable then this property does nothing.

dismissOnClickOutside

val dismissOnClickOutsideBoolean

Whether the popup can be dismissed by clicking outside the popup's bounds. If true, clicking outside the popup will call onDismissRequest.

excludeFromSystemGesture

val excludeFromSystemGestureBoolean

A flag to check whether to set the systemGestureExclusionRects. The default is true.

focusable

val focusableBoolean

Whether the popup is focusable. When true, the popup will receive IME events and key presses, such as when the back button is pressed.

securePolicy

val securePolicySecureFlagPolicy

Policy for how WindowManager.LayoutParams.FLAG_SECURE is set on the popup's window.

usePlatformDefaultWidth

val usePlatformDefaultWidthBoolean

Whether the width of the popup's content should be limited to the platform default, which is smaller than the screen width.

windowToken

val windowTokenIBinder?

An optional android.os.IBinder to be used as the window token for the popup window. In most cases, this can be left null, and the popup will use the token from the hosting Compose view (android.view.View.getApplicationWindowToken). However, this parameter is essential for cross-process scenarios. For instance, if a Service running in a different process needs to display a popup anchored to a window in the main application process, the main application's window token must be provided here. The provided token must be a validandroid.os.IBinder from an existing window and must have the necessary permissions to add sub-windows of the specifiedwindowType. Providing an invalid, stale, or permission-denied token will typically result in an android.view.WindowManager.BadTokenException when the popup attempts to show.

Example usage:

windowType

val windowTypeInt

An optional WindowManager.LayoutParams.type for the popup window. Defaults to WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL. Overriding this allows you to change the layer or behavior of the popup. For example, setting it to WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY can be used to display a popup on top of all other applications (which requires the android.Manifest.permission.SYSTEM_ALERT_WINDOW permission). Note: If you are displaying a popup from a non-Activity context (such as an android.app.Service) but still want it to be anchored to an existing application window, you should leave this as the default sub-panel type and instead provide the windowToken of the target application window.