英文:
Alternative of announceForAccessibility in Jetpack compose
问题
在Jetpack Compose中,是否有announceForAccessibility
的替代方法,可以自动为事件宣布文本?
英文:
is there any alternative of announceForAccessibility
in jetpack compose which will announce a text automatically for an event.
答案1
得分: 2
问题在于,辅助功能区域(live region)只会在屏幕上可见的文本时才进行语音提示,否则将被忽略。另一种方法是获取视图并使用 announceForAccessibility 自行进行语音提示。
val localView = LocalView.current
localView.announceForAccessibility("要宣布的文本")
英文:
Problem with live region is that it will only announce if the Text is visible on the screen, otherwise it will be ignored. An alternative would be to retrieve the view and use the announceForAccessibility itself.
val localView = LocalView.current
localView.announceForAccessibility("your text to be announced")
答案2
得分: 0
announceForAccessibility
是一个极端措施,我不确定你的用例,但请注意:
>注意:使用此API生成的事件没有语义含义,仅在特殊情况下适用。应用程序通常可以通过准确提供其UI的语义来实现较正确的辅助功能行为。它们不应该需要指定要向用户宣布的确切内容。
>
>...
>
>使用View#setAccessibilityLiveRegion(int)来通知用户有关用户界面中关键视图的更改。它们仍然应谨慎使用,因为它们可能在每次更新View时生成通知。
在大多数情况下,您可以在视图上使用liveRegion
属性。从文档中了解更多:
>Live region向辅助功能服务指示它们应自动通知用户有关节点的内容描述或文本的更改,或者有关节点的子节点(适用的情况下)的内容描述或文本的更改。
Text(text = "一些文本视图",
modifier = Modifier.semantics {
liveRegion = LiveRegionMode.Assertive
}
)
英文:
I'm not sure of your use case, but announceForAccessibility
is an extreme measure:
>Note: The event generated with this API carries no semantic meaning, and is appropriate only in exceptional situations. Apps can generally achieve correct behavior for accessibility by accurately supplying the semantics of their UI. They should not need to specify what exactly is announced to users.
>
>...
>
>Use View#setAccessibilityLiveRegion(int) to inform the user of changes to critical views within the user interface. These should still be used sparingly as they may generate announcements every time a View is updated.
In most cases you can use the liveRegion
attribute on a view. From the documentation:
>Live region indicates to accessibility services they should automatically notify the user about changes to the node's content description or text, or to the content descriptions or text of the node's children (where applicable).
Text(text = "Some text view",
modifier = Modifier.semantics {
liveRegion = LiveRegionMode.Assertive
}
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论