I'm working to make a HubDisclaimerView accessible with TalkBack and the role of "button" or "link" isn't being applied.
I've set a content description to announce what the text is, but the view does not inherit from Button or ImageView. It does have an onClickListener
and isClickable=true
. Yet no "Double Click to ..." or "Button" or "Link" accessibility features show in TalkBack mode or in the Local Context menu.
I'm wondering if there's a fix to making a custom view a Link for accessibility purposes? The AccessibilityEvent API seems to not be the right direction, since I'm hoping to add this to a row in a list which is acting as a Term & Conditions link.
You can add information inside onInitializeAccessibilityNodeInfo()
to tell accessibility services like Talkback that the view is clickable. I don't have your code, but wrote a trivial custom view to demonstrate this:
class MyTextView : TextView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
// ... other override methods
override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo?) {
super.onInitializeAccessibilityNodeInfo(info)
// With `null` as the second argument to `AccessibilityAction`, Talkback announces
// "double tap to activate". If a custom string is provided,
// Talkback announces "double tap to <custom string>".
val customClick = AccessibilityAction(AccessibilityNodeInfo.ACTION_CLICK, "foo")
info?.addAction(customClick)
}
}
There isn't a real reason to add a role, since Talkback will make the "double tap to X" announcements with this small change. If you absolutely wanted to set the role, you could do so as follows (but again, I'm not sure if anything is gained by doing so):
override fun getAccessibilityClassName(): CharSequence {
return Button::class.java.name
}
This makes Talkback add "Button" to the announcement, but adding a role in this manner is a hack. There's no guarantee that Talkback will continue to announce the view as a button just because you set the accessibilityClassName
. Stick with adding AccessibilityNodeInfo.ACTION_CLICK
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With