Skip to content

Instantly share code, notes, and snippets.

@miguelhincapie
Created April 4, 2020 03:45
Show Gist options
  • Save miguelhincapie/1735d3aab55abca9502baa19b07eeb72 to your computer and use it in GitHub Desktop.
Save miguelhincapie/1735d3aab55abca9502baa19b07eeb72 to your computer and use it in GitHub Desktop.
Snippet showing how to send accessibility focus to an specific UI element after TalkBack started.
/**
* With this function we are observing a specific accessibility service started/stopped: TalkBack
*/
private fun onTalkBackStateChanged(isOn: Boolean) {
if (isOn) {
accessibility_state.text = getString(R.string.accessibility_state_on)
accessibility_state.weakPostDelayed { sendFocusToTitle() }
} else {
accessibility_state.text = getString(R.string.accessibility_state_off)
}
}
private fun sendFocusToTitle() = with(accessibility_state) {
requestFocus()
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment