辅助功能对话框/DialogFragment 读取文本而不是内容描述

lig*_*365 5 android accessibility accessibilityservice talkback

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

<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" />
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

提前致谢。

ala*_*anv 4

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

基本上,您希望 onPopulateAccessibilityEvent() 使用内容描述而不是文本填充事件。

假设您扩展了 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());
}
Run Code Online (Sandbox Code Playgroud)

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