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

androidx.compose.ui.semantics

Interfaces

SemanticsModifier

A Modifier.Element that adds semantics key/value for use in testing, accessibility, and similar use cases.

SemanticsPropertyReceiver

Classes

AccessibilityAction

Data class for standard accessibility action.

AccessibilityRangeInfo

Data class for accessibility range information.

AccessibilityScrollState

The scroll state of this node if this node is scrollable.

CustomAccessibilityAction

Data class for custom accessibility action.

SemanticsConfiguration

Describes the semantic information associated with the owning component

SemanticsNode

A list of key/value pairs associated with a layout node or its subtree.

SemanticsOwner

Owns SemanticsNode objects and notifies listeners of changes to the semantics tree

SemanticsPropertyKey

Extension functions summary

For SemanticsPropertyReceiver
Unit
SemanticsPropertyReceiver.copyText(label: String? = null, action: () -> Boolean)

This function adds the SemanticsActions.CopyText to the SemanticsPropertyReceiver.

Unit
SemanticsPropertyReceiver.cutText(label: String? = null, action: () -> Boolean)

This function adds the SemanticsActions.CutText to the SemanticsPropertyReceiver.

Unit

Whether this element is a Dialog.

Unit

Whether this semantics node is disabled.

Unit

This function adds the SemanticsActions.GetTextLayoutResult to the SemanticsPropertyReceiver.

Unit

Whether this semantics node is hidden.

Unit
SemanticsPropertyReceiver.onClick(label: String? = null, action: () -> Boolean)

This function adds the SemanticsActions.OnClick to the SemanticsPropertyReceiver.

Unit
SemanticsPropertyReceiver.onLongClick(label: String? = null, action: () -> Boolean)

This function adds the SemanticsActions.OnLongClick to the SemanticsPropertyReceiver.

Unit
SemanticsPropertyReceiver.pasteText(label: String? = null, action: () -> Boolean)

This function adds the SemanticsActions.PasteText to the SemanticsPropertyReceiver.

Unit

Whether this semantics node represents a Popup.

Unit
SemanticsPropertyReceiver.scrollBy(label: String? = null, action: (x: Float, y: Float) -> Boolean)

This function adds the SemanticsActions.ScrollBy to the SemanticsPropertyReceiver.

Unit
SemanticsPropertyReceiver.setProgress(label: String? = null, action: (Float) -> Boolean)

This function adds the SemanticsActions.SetProgress to the SemanticsPropertyReceiver.

Unit
SemanticsPropertyReceiver.setSelection(label: String? = null, action: (startIndex: Int, endIndex: Int, traversalMode: Boolean) -> Boolean)

This function adds the SemanticsActions.SetSelection to the SemanticsPropertyReceiver.

Unit
SemanticsPropertyReceiver.setText(label: String? = null, action: (AnnotatedString) -> Boolean)

This function adds the SemanticsActions.SetText to the SemanticsPropertyReceiver.

For SemanticsOwner
List<SemanticsNode>

Finds all SemanticsNodes in the tree owned by this SemanticsOwner.

For SemanticsConfiguration
T?

For Modifier
Modifier
Modifier.semantics(mergeAllDescendants: Boolean = false, properties: SemanticsPropertyReceiver.() -> Unit)

Add semantics key/value for use in testing, accessibility, and similar use cases.

Extension properties summary

For SemanticsPropertyReceiver
String

Developer-set content description of the semantics node.

String

Developer-set state description of the semantics node.

AccessibilityRangeInfo

The node is a range with current value.

List<CustomAccessibilityAction>

Custom actions which are defined by app developers.

Boolean

Whether this semantics node is focused.

AccessibilityScrollState

The horizontal scroll state of this node if this node is scrollable.

String

Test tag attached to this semantics node.

AnnotatedString

Text of the semantics node.

TextRange

Text selection range for edit text.

AccessibilityScrollState

The vertical scroll state of this node if this node is scrollable.

Extension functions

copyText

fun SemanticsPropertyReceiver.copyText(
    label: String? = null,
    action: () -> Boolean
): Unit

This function adds the SemanticsActions.CopyText to the SemanticsPropertyReceiver.

Parameters
label: String? = null Optional label for this action.
action: () -> Boolean Action to be performed when the SemanticsActions.CopyText is called.

cutText

fun SemanticsPropertyReceiver.cutText(
    label: String? = null,
    action: () -> Boolean
): Unit

This function adds the SemanticsActions.CutText to the SemanticsPropertyReceiver.

Parameters
label: String? = null Optional label for this action.
action: () -> Boolean Action to be performed when the SemanticsActions.CutText is called.

dialog

fun SemanticsPropertyReceiver.dialog(): Unit

Whether this element is a Dialog. Not to be confused with if this element is part of a Dialog.

disabled

fun SemanticsPropertyReceiver.disabled(): Unit

Whether this semantics node is disabled.

getAllSemanticsNodes

fun SemanticsOwner.getAllSemanticsNodes(mergingEnabled: Boolean): List<SemanticsNode>

Finds all SemanticsNodes in the tree owned by this SemanticsOwner. Return the results in a list.

getOrNull

fun <T> SemanticsConfiguration.getOrNull(key: SemanticsPropertyKey<T>): T?

getTextLayoutResult

fun SemanticsPropertyReceiver.getTextLayoutResult(
    label: String? = null,
    action: (MutableList<TextLayoutResult>) -> Boolean
): Unit

This function adds the SemanticsActions.GetTextLayoutResult to the SemanticsPropertyReceiver.

Parameters
label: String? = null Optional label for this action.
action: (MutableList<TextLayoutResult>) -> Boolean Action to be performed when the SemanticsActions.GetTextLayoutResult is called.

hidden

fun SemanticsPropertyReceiver.hidden(): Unit

Whether this semantics node is hidden. A hidden node is a node that is not visible for accessibility.

onClick

fun SemanticsPropertyReceiver.onClick(
    label: String? = null,
    action: () -> Boolean
): Unit

This function adds the SemanticsActions.OnClick to the SemanticsPropertyReceiver.

Parameters
label: String? = null Optional label for this action.
action: () -> Boolean Action to be performed when the SemanticsActions.OnClick is called.

onLongClick

fun SemanticsPropertyReceiver.onLongClick(
    label: String? = null,
    action: () -> Boolean
): Unit

This function adds the SemanticsActions.OnLongClick to the SemanticsPropertyReceiver.

Parameters
label: String? = null Optional label for this action.
action: () -> Boolean Action to be performed when the SemanticsActions.OnLongClick is called.

pasteText

fun SemanticsPropertyReceiver.pasteText(
    label: String? = null,
    action: () -> Boolean
): Unit

This function adds the SemanticsActions.PasteText to the SemanticsPropertyReceiver.

Parameters
label: String? = null Optional label for this action.
action: () -> Boolean Action to be performed when the SemanticsActions.PasteText is called.
fun SemanticsPropertyReceiver.popup(): Unit

Whether this semantics node represents a Popup. Not to be confused with if this node is part of a Popup.

scrollBy

fun SemanticsPropertyReceiver.scrollBy(
    label: String? = null,
    action: (x: Float, y: Float) -> Boolean
): Unit

This function adds the SemanticsActions.ScrollBy to the SemanticsPropertyReceiver.

Parameters
label: String? = null Optional label for this action.
action: (x: Float, y: Float) -> Boolean Action to be performed when the SemanticsActions.ScrollBy is called.

semantics

fun Modifier.semantics(
    mergeAllDescendants: Boolean = false,
    properties: SemanticsPropertyReceiver.() -> Unit
): Modifier

Add semantics key/value for use in testing, accessibility, and similar use cases.

Parameters
mergeAllDescendants: Boolean = false Whether the semantic information provided by the owning component and all of its descendants should be treated as one logical entity.
properties: SemanticsPropertyReceiver.() -> Unit properties to add to the semantics. SemanticsPropertyReceiver will be provided in the scope to allow access for common properties and its values.

setProgress

fun SemanticsPropertyReceiver.setProgress(
    label: String? = null,
    action: (Float) -> Boolean
): Unit

This function adds the SemanticsActions.SetProgress to the SemanticsPropertyReceiver.

Parameters
label: String? = null Optional label for this action.
action: (Float) -> Boolean Action to be performed when the SemanticsActions.SetProgress is called.

setSelection

fun SemanticsPropertyReceiver.setSelection(
    label: String? = null,
    action: (startIndex: Int, endIndex: Int, traversalMode: Boolean) -> Boolean
): Unit

This function adds the SemanticsActions.SetSelection to the SemanticsPropertyReceiver. If this action is provided, the selection data must be provided using SemanticsProperties.TextSelectionRange.

Parameters
label: String? = null Optional label for this action.
action: (startIndex: Int, endIndex: Int, traversalMode: Boolean) -> Boolean Action to be performed when the SemanticsActions.SetSelection is called.

setText

fun SemanticsPropertyReceiver.setText(
    label: String? = null,
    action: (AnnotatedString) -> Boolean
): Unit

This function adds the SemanticsActions.SetText to the SemanticsPropertyReceiver.

Parameters
label: String? = null Optional label for this action.
action: (AnnotatedString) -> Boolean Action to be performed when the SemanticsActions.SetText is called.

Extension properties

accessibilityLabel

var SemanticsPropertyReceiver.accessibilityLabel: String

Developer-set content description of the semantics node. If this is not set, accessibility services will present the text of this node as content part.

accessibilityValue

var SemanticsPropertyReceiver.accessibilityValue: String

Developer-set state description of the semantics node. For example: on/off. If this not set, accessibility services will derive the state from other semantics properties, like AccessibilityRangeInfo, but it is not guaranteed and the format will be decided by accessibility services.

accessibilityValueRange

var SemanticsPropertyReceiver.accessibilityValueRange: AccessibilityRangeInfo

The node is a range with current value.

customActions

var SemanticsPropertyReceiver.customActions: List<CustomAccessibilityAction>

Custom actions which are defined by app developers.

See Also