I have a view that has a long press action handler. I use the content description to set the message Talkback speaks when the view gets focus.
Currently it says my content description right after getting a focus, and after a short pause says:
Double tap to activate, double tap and hold for long press
I want to change this message into something like
Double tap to "action 1", double tap and hold for "action 2"
Is there a way to do so?
I looked into onPopulateAccessibilityEvent()
, it gets TYPE_VIEW_ACCESSIBILITY_FOCUSED
event, but I wasn't able to change the desired message.
Am I missing something simple?
Use the code below for those who want to remove the all phrase ie. "double tap to".
This is basically calling the below code and
requestFocus
does not have any default talkback announcement associated with it.In API 21+, you can customize the action names by setting up custom actions on your View's
AccessibilityNodeInfo
. There are two approaches to this: 1) set anAccessibilityDelegate
and override theonInitializeAccessibilityNodeInfo
delegate method or 2) extend the view's class and overrideonInitializeAccessibilityNodeInfo
.Either way, you will be constructing a new AccessibilityAction and setting it on the node using AccessibilityNodeInfo.addAction.
If you chose to use a delegate, you would set a custom description for the click action as follows:
If you application targets API < 21, substitute the appropriate
*Compat
support library methods. The feature is not backported, so you won't get custom descriptions on API < 21, but you will be able to avoid explicit version checks in your application code.It seems
AccessibilityAction
has changed slightly since alanv posted his answer. Here is a working solution usingViewCompat
: