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)
                    }
                }
            }
上一篇:CSharp: Image Background Matting


下一篇:php-客户端处理与服务器端处理,哪个比较快?