You can set an AccessibilityDelegate
on a view to override things like how it describes itself in general:
ViewCompat.setAccessibilityDelegate(yourView, object : AccessibilityDelegateCompat(){
override fun onInitializeAccessibilityNodeInfo(host: View?, info: AccessibilityNodeInfoCompat?) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.let { it.text = "whatever" }
}
})
or you can override onPopulateAccessibilityEvent
(which handles triggered events like AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED
) and use event.getText()
, which gives you a List<CharSequence>
you can add
your description to. It really depends on what you're doing and how dynamic it needs to be.
I haven't found a good overview of all this stuff unfortunately, otherwise I'd link you to it. I think the delegates are what you need to look into though