SeekBar的Accessibility
程序员文章站
2022-06-09 23:07:50
SeekBar的Accessibility最近在做公司项目的Accessibility,刚好做到了关于如果自定义seekbar的contentDescription。其实逻辑就是"偷龙转凤"的思想. 意思就是真正执行的Accessibility的是另外一个view,比如说你可以用一个Textview.主要实现功能如下:sbDistance ->seekbartvTitle -> Textview sbDistance.accessibilityDelegate = object :...
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)
}
}
}
本文地址:https://blog.csdn.net/qq_32726703/article/details/110240565