辅助功能对话框/DialogFragment 读取文本而不是内容描述 [英] Accessibility Dialog/DialogFragment reads text instead of content description

查看:46
本文介绍了辅助功能对话框/DialogFragment 读取文本而不是内容描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对话框,几乎没有文本视图.对于每个文本视图,我都设置了不同的内容描述和文本.例如.

I have a dialog, that has few textviews. For each textview I have set different content description and text. For eg.

<TextView
    android:id="@+id/tv_3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="TV 3"
    android:text="Text Number 3" />

当我向用户显示对话框时,Talkback 会读取每个文本视图的文本(即文本编号 3),而不是内容描述(即 TV 3).

When I show the dialog to the user, Talkback reads the text (ie. Text Number 3) of each textview and not the content description (ie. TV 3).

但是,如果我将鼠标悬停在任何文本视图上,Talkback 会读取内容描述.

However if I hover on any textview, Talkback reads the content description.

如何让它在显示对话框时读取内容描述?

How do I make it read the content description when the dialog is shown?

PS:我曾尝试在布局中以及通过代码设置内容描述,但没有成功

PS: I have tried to set the content description in layout as well as thru code but no luck

提前致谢.

推荐答案

这是顶级 AccessibilityEvents 如何聚合其文本的副作用.这可能是需要在 TalkBack 中修复的问题,但您可以通过扩展 TextView 或在视图上设置 AccessibilityDelegate 在您的应用中解决这个问题.

This is a side-effect of how top-level AccessibilityEvents aggregate their text. This is probably something that needs to be fixed within TalkBack, but you could address it the hard way in your app by extending TextView or setting an AccessibilityDelegate on the view.

基本上,您想让 onPopulateAccessibilityEvent() 用内容描述而不是文本填充事件.

Basically, you want to make onPopulateAccessibilityEvent() populate the event with the content description, rather than the text.

假设您扩展了 TextView:

Let's assume you extend TextView:

public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    // The super method would normally add the text, but we want to
    // add the content description instead. No need to call super.
    event.getText().add(getContentDescription());
}

请记住,在大多数情况下,您希望文本视图的内容描述和视觉外观匹配,并且覆盖默认行为可能会导致意外结果.一般建议不要在文本视图上设置内容描述.

Keep in mind that in most situations you want the content description and visual appearance of a text view to match, and that overriding the default behavior may lead to unexpected results. The general recommendation is to not set content descriptions on text views.

这篇关于辅助功能对话框/DialogFragment 读取文本而不是内容描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆