5

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

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

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

显示对话框时如何使其读取内容描述?

PS:我试图在布局中设置内容描述以及通过代码但没有运气

提前致谢。

4

2 回答 2

4

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.

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

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.

于 2014-08-11T23:07:03.520 回答
0

有趣的是,即使该视图有内容描述,它也会选择第一个可视文本。这是一种禁用自动读取的第一个文本的方法。

Dialog.getWindow().getDecordView().setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO)
于 2021-03-13T02:54:22.880 回答