【发布时间】:2022-06-10 18:41:06
【问题描述】:
假设我有一个带有行的列。每行都是一个逻辑单元,我希望 Talkback 逐行浏览列,而不选择行的后代。使用mergeDescendants = true 可以轻松实现这一目标
现在,我为 Row 定制了一个 contentDescription,它提供了更自然的描述。如何忽略要阅读的后代文本,以防止信息加倍?
tl;dr: 当使用mergeDescendants;如何让 Talkback 替换而不是合并后代的 contentDescriptions?
@Composable
fun Greeting() {
// Goal: Each row is a single entity for talkback, that has a content desccription describing the entire tow
// descendants should not be focused when navigating by swipe w/ talkback
// "Greeting for Android X" should be read, descendants should not be read automatically.
Column(modifier = Modifier.padding(20.dp)) {// Screen padding
Box(
// "greeting for Android 1 ... Hello Android! ... How do you do?" :-(
// descendants can not be selected individually :-)
Modifier.semantics(mergeDescendants = true) {
contentDescription = "greeting for Android 1"
}
) {
Row {
Text(text = "Hello Android!", modifier = Modifier.padding(32.dp))
Text(text = "How do you do?", modifier = Modifier.padding(32.dp))
}
}
Box(
// "greeting for Android 2" :-)
// descendants will be traversed next :-(
Modifier.semantics {
contentDescription = "greeting for Android 2"
}
) {
Row {
Text(text = "Hello Android!", modifier = Modifier.padding(32.dp))
Text(text = "How do you do?", modifier = Modifier.padding(32.dp))
}
}
Box(
// "greeting for Android 3" :-)
// descendants can not be selected individually :-)
// When using tap to speak rather than swipe, it is hard to select the row:
// Only when tapping empty space will the row be selected.
// When tapping either text element,nothing happens. :-(
// Expected: the row is selected and "greeting for android 3" is read when
// I tap anywhere inside it's bounds
Modifier.semantics {
contentDescription = "greeting for Android 3"
}
) {
Row(Modifier.clearAndSetSemantics {}) {
Text(text = "Hello Android!", modifier = Modifier.padding(32.dp))
Text(text = "How do you do?", modifier = Modifier.padding(32.dp))
}
}
}
}
【问题讨论】:
-
嗨@nino-van-hooff,你成功了吗?我也有同样的问题...
标签: android accessibility android-jetpack-compose talkback