Jetpack Compose 中 announceForAccessibility 的替代方法是:

huangapple go评论51阅读模式
英文:

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
    }
)

huangapple
  • 本文由 发表于 2023年6月5日 10:42:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76403237.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定