简体   繁体   中英

Talkback announces focused button's label first before the title on Android TV

I'm implementing a screen for Android TV, which has a screen title and a button on the left side. And a list of custom views/rows(selectable/clickable), arranged vertically, on the right side of the page.

We want the button on the left to be in focus when the user sees that screen. For that, I'm calling button.requestFocus() in the onResume() of the fragment.

This breaks the accessibility. When talkback is enabled, the first thing announced is the button's label. What I want is to announce the title first and then the button's label.

I tried to announce a custom text(could be title) by

rootView.announceForAccessibility(accessibilityText)

where rootView is the root of the xml layout and accessibilityText a text which needs to be announced.

But it doesn't help, and the button's label gets the priority.

How can I solve the issue?

I would ask you to consider WCAG Guideline 3.2.1:

The intent of this Success Criterion is to ensure that functionality is predictable as visitors navigate their way through a document. Any component that is able to trigger an event when it receives focus must not change the context. Examples of changing context when a component receives focus include, but are not limited to:

  • forms submitted automatically when a component receives focus;
  • new windows launched when a component receives focus;
  • focus is changed to another component when that component receives focus; <-- emphasis here

Also a quote from the Android Accessibility Team :

So something similar that people like to do is manage accessibility focus themselves. And again, this is a bad idea. accessibility focus has to be determined by the accessibility service, and just like announcements this creates an inconsistency in experience. And actually, that one of the biggest issues that accessibility users face, inconsistency, across applications and over time.

With that said, you may want to consider looking at ensuring the focus order / priority of the component using the following attributes:

android:nextFocusUp
android:nextFocusDown
android:nextFocusLeft
android:nextFocusRight

And also ensure that any group component that may get highlighted has the importantForAccessibility attribute set.

I'd like to try help some more, but without an example XML file, it's difficult to get to your particular use case. Have you tried testing the view layout with accessibility users?

I took a cue from this article by ATAUL MUNIM. I added a check if talkback is enabled, before requesting the focus explicitly.

 protected fun isTalkBackEnabled(): Boolean {
    val a11yServices = context?.getSystemService(ACCESSIBILITY_SERVICE) as? AccessibilityManager
    return a11yServices?.isTouchExplorationEnabled?:false
}

and

if(isTalkBackEnabled().not()) {
   button.requestFocus()
}

This solution pretty much bailed me out from the problem I was facing. It was also the only way forward for me because my app's min API level is 21 which eliminates the option to use android:screenReaderFocusable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM