How to make TalkBack read Android accessibility events in order without cutting them off

2.6k Views Asked by At

I have a filters view which upon dismissing, I'd like to do 2 accessibility things:

  • announce "$listSize items in list" since applying the filters will change the list size
  • set focus to the "Add filters" button

I tried the following:

filtersButton.announceForAccessibility("$listSize items in list")
filtersButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)

I would expect TalkBack to read, in order:

  • "20 items in list"
  • "Filters button"

However, it usually skips the first read-out and only reads the text on filtersButton. Sometimes it will read only part of the first before skipping to the second.

How do I force TalkBack to read out both accessibility events?

1

There are 1 best solutions below

0
On

It is good practice, and a recommended approach, to make the textual and audible information similar. Try to avoid announcements, instead make the screen reader read the information that is shown. The method announceForAccessibility() is intended to inform visual changes that otherwise would be unnoticed.

Do you have a view on your screen that shows the total number of items? If you don't have a visual clue of the item count, you shouldn't announce it on TalkBack. Either the information is important and you should present it visually to all users, or the information is not that important to be displayed on the screen, and shouldn't be announced on the screen reader.

If you have it visible on the screen, you may use the AccessibilityLiveRegion to let the reader announce the changed value, and keep the focus on the Add filters button. Another approach would be simply setting the first focus to the view showing the items list count, and letting the user navigate to the button next.

ViewCompat.setAccessibilityLiveRegion(itemCountTextView, ACCESSIBILITY_LIVE_REGION_POLITE)