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

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

问题描述

我有一个对话框,该对话框的文本视图很少。
我为每个textview设置了不同的内容描述和文本。
例如

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)

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

但是,如果我将鼠标悬停在任何textview上,则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

预先感谢。

推荐答案

这是顶级AccessibilityEvent如何聚合其文本的副作用。这可能是需要在话语提示中修复的,但是您可以通过扩展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.

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

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