Created
April 4, 2020 03:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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