Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessibility Dialog/DialogFragment reads text instead of content description

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.

like image 281
light365 Avatar asked Oct 01 '22 03:10

light365


1 Answers

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.

like image 165
alanv Avatar answered Oct 20 '22 07:10

alanv