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 an AccessibilityDelegate
and override the onInitializeAccessibilityNodeInfo
delegate method or 2) extend the view's class and override onInitializeAccessibilityNodeInfo
.
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:
view.setAccessibilityDelegate(new AccessibilityDelegate() {
@Override
public void onInitializeAccessibilityNodeInfo(
View v, AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(v, info);
// A custom action description. For example, you could use "pause"
// to have TalkBack speak "double-tap to pause."
CharSequence description = getResources().getText(R.string.my_click_desc);
AccessibilityAction customClick = new AccessibilityAction(
AccessibilityAction.ACTION_CLICK, description);
info.addAction(customClick);
}
});
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.