By default, clickable Views on Android will be rendered with a usage hint that's read aloud (if TalkBack is enabled and the user focuses on that View) after the content description:
"Double tap to activate"
Can I change this so it reads out something less abstract and more specific to my app? Like:
"Double tap to play video"
Yes, this is absolutely possible!
Overriding the
onInitializeAccessibilityNodeInfo
methodIf you have a custom View, you can override the
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
method and add an action with theACTION_CLICK
ID, to override the label:If that View has a click listener, then by adding this new
Action
, you'll have overridden the default label so TalkBack will say "Double tap to " instead.This is only available on API 21 - what if you wanted something that worked on a lower API version or wanted to set a custom usage hint on a non-custom View? You can use
ViewCompat
andAccessibilityDelegateCompat
!Using an AccessibilityDelegate instead
It's very similar - you can override the equivalent method in a custom AccessibilityDelegate that you extend:
then to use it, you set the delegate with
ViewCompat
:Using accessibilitools
Novoda has a utility library to help with accessibility on Android. This includes some tools to help set usage hints:
I wrote a blogpost which is an overview of accessibilitools (I am also a contributor to the library).