有没有办法改变jetpack组合语义合并后代的顺序

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

我使用 Jetpack Compose v1.5.0 创建一个包含两个文本控件的行,并通过设置 mergeDescendants = true 将两个文本合并到一个语义组中:

Row(
    modifier = Modifier.semantics(mergeDescendants = true) {  }
) {
    Text("text 1")
    Text("text 2")
}

当对讲服务聚焦于行时,对讲将按正常顺序读出文本:“文本一文本二”。

但我的目标是更改文本的顺序,以便对讲应读出:“文本二文本一”。可以吗?

我在 https://developer.android.com/jetpack/compose/accessibility 阅读了 Android 文档 但我没有找到解决方案。我也尝试了

isTraversalGroup
traversalIndex
,但没有成功:

Row(
    modifier = Modifier.semantics(mergeDescendants = true) { isTraversalGroup = true }
) {
    Text(
        text = "text 1",
        modifier = Modifier.semantics() { traversalIndex = 2f }
    )
    Text(
        text = "text 2",
        modifier = Modifier.semantics() { traversalIndex = 1f }
    )
}
android android-jetpack-compose talkback
1个回答
0
投票

如本期所述:https://issuetracker.google.com/issues/285043826

您可以使用

zIndex
修饰符来实现您所需要的。

这是示例的固定版本:

Row(
    modifier = Modifier.semantics(mergeDescendants = true) { isTraversalGroup = true }
) {
      Text(text = "text 1", modifier = Modifier.zIndex(1f))
      Text(text = "text 2", modifier = Modifier.zIndex(0f))
}
© www.soinside.com 2019 - 2024. All rights reserved.