Accessibility Dialog/DialogFragment reads text instead of content description

人盡茶涼 提交于 2019-12-11 01:57:14

问题


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" />

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

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: I have tried to set the content description in layout as well as thru code but no luck

Thanks in advance.


回答1:


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.



来源:https://stackoverflow.com/questions/25169273/accessibility-dialog-dialogfragment-reads-text-instead-of-content-description

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!