ActionProvider

public abstract class ActionProvider

Known direct subclasses
MediaRouteActionProvider

The media route action provider displays a media route button in the application's ActionBar to allow the user to select routes and to control the currently selected route.

ShareActionProvider

Provides a share action, which is suitable for an activity's app bar.


This class is a mediator for accomplishing a given task, for example sharing a file. It is responsible for creating a view that performs an action that accomplishes the task. This class also implements other functions such a performing a default action.

An ActionProvider can be optionally specified for a android.view.MenuItem and in such a case it will be responsible for creating the action view that appears in the android.app.ActionBar as a substitute for the menu item when the item is displayed as an action item. Also the provider is responsible for performing a default action if a menu item placed on the overflow menu of the ActionBar is selected and none of the menu item callbacks has handled the selection. For this case the provider can also optionally provide a sub-menu for accomplishing the task at hand.

There are two ways for using an action provider for creating and handling of action views:

  • Setting the action provider on a android.view.MenuItem directly by calling setActionProvider.
  • Declaring the action provider in the menu XML resource. For example:
      <item android:id="@+id/my_menu_item"
        android:title="@string/my_menu_item_title"
        android:icon="@drawable/my_menu_item_icon"
        android:showAsAction="ifRoom"
        android:actionProviderClass="foo.bar.SomeActionProvider" />
    
### Creating a custom action provider

To create a custom action provider, extend ActionProvider and implement its callback methods as necessary. In particular, implement the following methods:

Summary

Nested types

ActionProvider.VisibilityListener

Listens to changes in visibility as reported by refreshVisibility.

Public constructors

Creates a new instance.

Public methods

@NonNull Context

Gets the context associated with this action provider.

boolean

Determines if this ActionProvider has a submenu associated with it.

boolean

If overridesItemVisibility returns true, the return value of this method will help determine the visibility of the MenuItem this ActionProvider is bound to.

abstract @NonNull View

Factory method for creating new action views.

@NonNull View