TextField onValueChange - 宣布附加语义

问题描述 投票:0回答:1

使用自定义的

TextField
实现,但它仍然使用 compose 提供的
BasicTextField

BasicTextField(
    modifier = Modifier
        .fillMaxWidth()
        .semantics(mergeDescendants = true) {
            this.contentDescription = (contentDescription
                ?: "") + (if (!placeholder.isNullOrBlank() && value.isBlank()) placeholder
                else value) + counterText
            if (disabled) {
               disabled()
            }
        },
    value = value,
    onValueChange = { newValue ->
        onValueChange(newValue)
    },
    enabled = enabled,
    readOnly = readOnly,
    textStyle = mergedTextStyle,
    cursorBrush = SolidColor(contentColor),
    keyboardOptions = keyboardOptions,
    keyboardActions = keyboardActions,
    interactionSource = interactionSource,
    singleLine = singleLine,
    maxLines = maxL,
    minLines = minL
) {...

语义读起来完全符合我希望它们在原始焦点上的样子。但是当我输入一个字符时,它读取的只是该字符。

已输入密钥,

A
=
“A”

我希望宣布语义

“A, ${counterText}”
。但我找不到一种方法来与看起来像
TextInputService
或类似的东西联系起来。我是否缺少一个概念?

android android-jetpack-compose semantics
1个回答
0
投票

所以我找到了我正在寻找的东西。这很烦人,因为我似乎无法在 Compose Developer 说明中找到示例,但它效果很好。

Modifier.semantics(mergeDescendants = true) {
    …
    liveRegion = LiveRegionMode.Polite // ..Assertive if you want immediate response on change.
}

文本会说

”A, $stateDescription, $contentDescription”

© www.soinside.com 2019 - 2024. All rights reserved.