代码如下:
private fun requestAccessibilityFocus(view:View){
val task = Runnable {
// 主动设置读屏控件焦点
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}
val worker = Executors.newSingleThreadScheduledExecutor()
// 延迟执行 (不加延迟 sendAccessibilityEvent可能会出现竞争,导致焦点被覆盖造成设置失效)
worker.schedule(task, 1, TimeUnit.SECONDS)
}