HarmonyOS NEXT应用元服务开发按钮标注场景

‌HarmonyOS NEXT应用元服务开发中,对于用户可点击等操作的按钮,如果不是文本类控件,需要通过给出标注信息。‌ 标注信息包括用户自定义的控件中的虚拟按钮区域,否则可能会导致屏幕朗读用户无法完成对应的功能。此类控件在进行标注时,标注文本不要包含控件类型、“单指双击即可打开”之类的字符串,这部分指引由屏幕朗读根据控件类型、控件状态,并结合用户是否开启了“新手指引”自动追加朗读‌。

例如,对于Image组件(它实际上是一个播放/暂停按钮),通过设置accessibilityText属性提供标注信息。例如:

.const RESOURCE_STR_PLAY = $r('app.media.play')

.const RESOURCE_STR_PAUSE = $r('app.media.pause')

...

.play() {

    // play audio file

}

.pause() {

    // pause playing of audio file

}

.build() {

    NavDestination() {

        Column() {

            Flex({

                direction: FlexDirection.Column,

                alignItems: ItemAlign.Center,

                justifyContent: FlexAlign.Center,

            }) {

                Row() {

                    Image(this.isPlaying ? RESOURCE_STR_PAUSE : RESOURCE_STR_PLAY)

                        .width(50)

                        .height(50)

                        .onClick(() => {

                        this.isPlaying = !this.isPlaying

                        if (this.isPlaying) {

                            this.play()

                        } else {

                            this.pause()

                        }

                    })

                }

            }

        }

    }

}

猜你喜欢

转载自blog.csdn.net/Rverdoser/article/details/142827932