JetPack组成:忽略后代'内容描述
假设我有一个带有行的列。每一行都是逻辑单元,我想对话以逐行导航,而无需选择该行的后代。 现在,使用MERGEDESCENDANTS = true
现在可以很容易地实现这一点
,我有一个针对该行的量身定制的内容描述,可以提供更自然的描述。我如何忽略后代的文本要阅读,以防止将信息加倍?
tl; dr:使用合并Escendants
;如何使对讲替换而不是合并后代的内容描述?
@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))
}
}
}
}
Let's say I have a Column with Rows. Each Row is a logical unit and I want Talkback to navigate through the Column Row by Row, without selecting and descendants of the row. That's easily achievable with mergeDescendants = true
Now, I have a tailored contentDescription for the Row, that provides a more natural description. How do I ignore the descendant's text to be read, to prevent doubling the information?
tl;dr: When using mergeDescendants
; how do I make Talkback replace rather than merge the descendants' 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))
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设在您上方呈现的代码中,
box
表示您的“行”。首先尝试合并Box的孩子的语义属性,然后通过将以下修饰符应用于Box来清除所有内容并设置自定义内容说明:此外,您还可以在每个Box的孩子上明确调用以下以下内容,以确保其语义属性忽略:
I assume that in the code you presented above the top level
Box
represents your "rows". Try firstly merging semantic properties of Box's children and then clearing all of them and setting your custom content description by applying the following modifier to Box:Additionally, you could also explicitly call the following on each Box's children to ensure their semantic properties are ignored: