0

I want to give following sequence of Talkback events when user navigates to a DialogFragment,

1) On navigating to DialogFragment, initial focus should be on positive Button

2) title+description of the dialog should get announced without focusing it's TextView

2) and lastly it should read out positive Button's content description

override fun onResume() {
        super.onResume()
        positiveButton.contentDescription = "OK"
        positiveButton.announceForAccessibility(dialogArguments.title+dialogArguments.message)
        positiveButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT)
        ViewCompat.setAccessibilityDelegate(positiveButton, object : AccessibilityDelegateCompat() {
            override fun onPopulateAccessibilityEvent(host: View?, event: AccessibilityEvent?) {
                super.onPopulateAccessibilityEvent(host, event)
                event?.text?.clear()
                positiveButton.performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null)
            }
        })
    }

The above code works as per the required sequence but it doesn’t announce class type i.e Button and action description 'press select to activate' at the end

musica
  • 1,373
  • 3
  • 15
  • 34

1 Answers1

1

You have quite a bit of code here that tries to control the TalkBack user experience. We generally recommend just providing correct information to the accessibility API and allowing TalkBack to handle communicating it to the user.

We recommend not trying to set accessibility focus at all. Setting it on every accessibility event could lead to some pretty undesirable side effects.

What if you just delete all of this code, except maybe the content description if the button doesn't have text (although that could be in xml)?

We are aware that TalkBack's initial focus in dialogs isn't always optimal, but since TalkBack does it, it should be consistent across apps. And if we find a better solution, it will then be consistently better across apps. Workaround like this code can break whenever TalkBack changes.

Phil Weaver
  • 738
  • 3
  • 7