to top
Android APIs
public static class

View.AccessibilityDelegate

extends Object
java.lang.Object
   ↳ android.view.View.AccessibilityDelegate

Class Overview

This class represents a delegate that can be registered in a View to enhance accessibility support via composition rather via inheritance. It is specifically targeted to widget developers that extend basic View classes i.e. classes in package android.view, that would like their applications to be backwards compatible.

Developer Guides

For more information about making applications accessible, read the Accessibility developer guide.

A scenario in which a developer would like to use an accessibility delegate is overriding a method introduced in a later API version then the minimal API version supported by the application. For example, the method onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) is not available in API version 4 when the accessibility APIs were first introduced. If a developer would like his application to run on API version 4 devices (assuming all other APIs used by the application are version 4 or lower) and take advantage of this method, instead of overriding the method which would break the application's backwards compatibility, he can override the corresponding method in this delegate and register the delegate in the target View if the API version of the system is high enough i.e. the API version is same or higher to the API version that introduced onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo).

Here is an example implementation:

if (Build.VERSION.SDK_INT >= 14) { // If the API version is equal of higher than the version in // which onInitializeAccessibilityNodeInfo was introduced we // register a delegate with a customized implementation. View view = findViewById(R.id.view_id); view.setAccessibilityDelegate(new AccessibilityDelegate() { public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { // Let the default implementation populate the info. super.onInitializeAccessibilityNodeInfo(host, info); // Set some other information. info.setEnabled(host.isEnabled()); } }); }

This delegate contains methods that correspond to the accessibility methods in View. If a delegate has been specified the implementation in View hands off handling to the corresponding method in this delegate. The default implementation the delegate methods behaves exactly as the corresponding method in View for the case of no accessibility delegate been set. Hence, to customize the behavior of a View method, clients can override only the corresponding delegate method without altering the behavior of the rest accessibility related methods of the host view.

Summary

Public Constructors
View.AccessibilityDelegate()
Public Methods
boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event)
Dispatches an AccessibilityEvent to the host View first and then to its children for adding their text content to the event.
AccessibilityNodeProvider getAccessibilityNodeProvider(View host)
Gets the provider for managing a virtual view hierarchy rooted at this View and reported to AccessibilityServices that explore the window content.
void onInitializeAccessibilityEvent(View host, AccessibilityEvent event)
Initializes an AccessibilityEvent with information about the the host View which is the event source.
void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about the host view.
void onPopulateAccessibilityEvent(View host, AccessibilityEvent event)
Gives a chance to the host View to populate the accessibility event with its text content.
boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, AccessibilityEvent event)
Called when a child of the host View has requested sending an AccessibilityEvent and gives an opportunity to the parent (the host) to augment the event.
boolean performAccessibilityAction(View host, int action, Bundle args)
Performs the specified accessibility action on the view.
void sendAccessibilityEvent(View host, int eventType)
Sends an accessibility event of the given type.
void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event)
Sends an accessibility event.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public View.AccessibilityDelegate ()

Added in API level 14

Public Methods

public boolean dispatchPopulateAccessibilityEvent (View host, AccessibilityEvent event)

Added in API level 14

Dispatches an AccessibilityEvent to the host View first and then to its children for adding their text content to the event.

The default implementation behaves as View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) for the case of no accessibility delegate been set.

Parameters
host The View hosting the delegate.
event The event.
Returns
  • True if the event population was completed.

public AccessibilityNodeProvider getAccessibilityNodeProvider (View host)

Added in API level 16

Gets the provider for managing a virtual view hierarchy rooted at this View and reported to AccessibilityServices that explore the window content.

The default implementation behaves as View#getAccessibilityNodeProvider() for the case of no accessibility delegate been set.

Returns
  • The provider.

public void onInitializeAccessibilityEvent (View host, AccessibilityEvent event)

Added in API level 14

Initializes an AccessibilityEvent with information about the the host View which is the event source.

The default implementation behaves as View#onInitializeAccessibilityEvent(AccessibilityEvent) for the case of no accessibility delegate been set.

Parameters
host The View hosting the delegate.
event The event to initialize.

public void onInitializeAccessibilityNodeInfo (View host, AccessibilityNodeInfo info)

Added in API level 14

Initializes an AccessibilityNodeInfo with information about the host view.

The default implementation behaves as View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) for the case of no accessibility delegate been set.

Parameters
host The View hosting the delegate.
info The instance to initialize.

public void onPopulateAccessibilityEvent (View host, AccessibilityEvent event)

Added in API level 14

Gives a chance to the host View to populate the accessibility event with its text content.

The default implementation behaves as View#onPopulateAccessibilityEvent(AccessibilityEvent) for the case of no accessibility delegate been set.

Parameters
host The View hosting the delegate.
event The accessibility event which to populate.

public boolean onRequestSendAccessibilityEvent (ViewGroup host, View child, AccessibilityEvent event)

Added in API level 14

Called when a child of the host View has requested sending an AccessibilityEvent and gives an opportunity to the parent (the host) to augment the event.

The default implementation behaves as ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) for the case of no accessibility delegate been set.

Parameters
host The View hosting the delegate.
child The child which requests sending the event.
event The event to be sent.
Returns
  • True if the event should be sent

public boolean performAccessibilityAction (View host, int action, Bundle args)

Added in API level 16

Performs the specified accessibility action on the view. For possible accessibility actions look at AccessibilityNodeInfo.

The default implementation behaves as View#performAccessibilityAction(int, Bundle) for the case of no accessibility delegate been set.

Parameters
action The action to perform.
Returns
  • Whether the action was performed.

public void sendAccessibilityEvent (View host, int eventType)

Added in API level 14

Sends an accessibility event of the given type. If accessibility is not enabled this method has no effect.

The default implementation behaves as View#sendAccessibilityEvent(int) for the case of no accessibility delegate been set.

Parameters
host The View hosting the delegate.
eventType The type of the event to send.

public void sendAccessibilityEventUnchecked (View host, AccessibilityEvent event)

Added in API level 14

Sends an accessibility event. This method behaves exactly as sendAccessibilityEvent(View, int) but takes as an argument an empty AccessibilityEvent and does not perform a check whether accessibility is enabled.

The default implementation behaves as View#sendAccessibilityEventUnchecked(AccessibilityEvent) for the case of no accessibility delegate been set.

Parameters
host The View hosting the delegate.
event The event to send.