其他分享
首页 > 其他分享> > SeekBar的Accessibility

SeekBar的Accessibility

作者:互联网

SeekBar的Accessibility

最近在做公司项目的Accessibility,刚好做到了关于如果自定义seekbar的contentDescription。其实逻辑就是"偷龙转凤"的思想. 意思就是真正执行的Accessibility的是另外一个view,比如说你可以用一个Textview.

主要实现功能如下:
sbDistance ->seekbar
tvTitle -> Textview

   sbDistance.accessibilityDelegate = object : View.AccessibilityDelegate() {
                override fun onInitializeAccessibilityEvent(host: View, event: AccessibilityEvent) {
                    super.onInitializeAccessibilityEvent(host, event)
                    if (event.eventType != AccessibilityEvent.TYPE_VIEW_SELECTED) {
                        val content=context.getString(R.string.content_description_distance,
                                distances[sbDistance.progress / 10])
                        tvTitle.announceForAccessibility(content)
                    }
                }

                override fun sendAccessibilityEvent(host: View, eventType: Int) {
                    val newEvent = if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
                        AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED
                    } else {
                        eventType
                    }
                    super.sendAccessibilityEvent(host, newEvent)
                }

                override fun sendAccessibilityEventUnchecked(host: View, event: AccessibilityEvent) {
                    if (event.eventType != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED
                            && event.eventType != AccessibilityEvent.TYPE_VIEW_SELECTED) {
                        super.sendAccessibilityEventUnchecked(host, event)
                    }
                }
            }

标签:SeekBar,eventType,AccessibilityEvent,Accessibility,host,TYPE,event
来源: https://blog.csdn.net/qq_32726703/article/details/110240565