Last active
January 8, 2018 01:23
-
-
Save mataanin/d59f8f75c36149aece6f4777bbba40da to your computer and use it in GitHub Desktop.
Reliable focus on a view on Android
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
// Sample using RxJava 1.x, Kotlin | |
var offSwitch = false | |
Observable | |
.interval(0, 100L, TimeUnit.MILLISECONDS) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.takeIf { !offSwitch } | |
.subscribe { | |
// try to focus every 100 milliseconds until the view or any of its children is focused | |
view.accessibilityFullFocus() | |
offSwitch = view.isAccessibilityFocused || view.hasAccessibilityFocusedChild | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment