ActionBar


public abstract class ActionBar


A primary toolbar within the activity that may display the activity title, application-level navigation affordances, and other interactive items.

The action bar appears at the top of an activity's window when the activity uses the AppCompat's AppCompat theme (or one of its descendant themes). You may otherwise add the action bar by calling requestFeature(FEATURE_SUPPORT_ACTION_BAR) or by declaring it in a custom theme with the windowActionBar property.

The action bar may be represented by any Toolbar widget within the application layout. The application may signal to the Activity which Toolbar should be treated as the Activity's action bar. Activities that use this feature should use one of the supplied .NoActionBar themes, set the windowActionBar attribute to false or otherwise not request the window feature.

If your activity has an options menu, you can make select items accessible directly from the action bar as "action items". You can also modify various characteristics of the action bar or remove it completely.

The navigation button (formerly "Home") takes over the space previously occupied by the application icon. Apps wishing to express a stronger branding should use their brand colors heavily in the action bar and other application chrome or use a logo in place of their standard title text.

From your activity, you can retrieve an instance of ActionBar by calling getSupportActionBar getSupportActionBar()}.

In some cases, the action bar may be overlayed by another bar that enables contextual actions, using an ActionMode. For example, when the user selects one or more items in your activity, you can enable an action mode that offers actions specific to the selected items, with a UI that temporarily replaces the action bar. Although the UI may occupy the same space, the ActionMode APIs are distinct and independent from those for ActionBar.

Summary

Nested types

Per-child layout information associated with action bar custom views.

Listener for receiving events when action bar menus are shown or hidden.

This interface is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

public abstract class ActionBar.Tab

This class is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

public interface ActionBar.TabListener

This interface is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

Constants

static final int

Display the 'home' element such that it appears as an 'up' affordance. e.g. show an arrow to the left indicating the action that will be taken.

static final int

Show the custom view if one has been set.

static final int

Show 'home' elements in this action bar, leaving more space for other navigation elements.

static final int

Show the activity title and subtitle, if present.

static final int

Use logo instead of icon if available.

static final int

This field is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

static final int

This field is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

static final int

This field is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

Public constructors

Public methods

abstract void

Add a listener that will respond to menu visibility change events.

abstract void

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract void
addTab(ActionBar.Tab tab, int position)

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract void
addTab(ActionBar.Tab tab, boolean setSelected)

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract void
addTab(ActionBar.Tab tab, int position, boolean setSelected)

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract View
abstract int
float

Get the Z-axis elevation of the action bar in pixels.

abstract int

Retrieve the current height of the ActionBar.

int

Return the current vertical offset of the action bar.

abstract int

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract int

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract int

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract @Nullable ActionBar.Tab

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract @Nullable CharSequence

Returns the current ActionBar subtitle in standard mode.

abstract ActionBar.Tab
getTabAt(int index)

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract int

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

Context

Returns a Context with an appropriate theme for creating views that will appear in the action bar.

abstract @Nullable CharSequence

Returns the current ActionBar title in standard mode.

abstract void

Hide the ActionBar if it is currently showing.

boolean

Return whether the action bar is configured to scroll out of sight along with a nested scrolling child.

abstract boolean
abstract ActionBar.Tab

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract void

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract void

Remove a menu visibility listener.

abstract void

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract void
removeTabAt(int position)

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract void

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract void

Set the ActionBar's background.

abstract void
setCustomView(int resId)

Set the action bar into custom navigation mode, supplying a view for custom navigation.

abstract void

Set the action bar into custom navigation mode, supplying a view for custom navigation.

abstract void

Set the action bar into custom navigation mode, supplying a view for custom navigation.

abstract void
setDisplayHomeAsUpEnabled(boolean showHomeAsUp)

Set whether home should be displayed as an "up" affordance.

abstract void
setDisplayOptions(int options)

Set display options.

abstract void
setDisplayOptions(int options, int mask)

Set selected display options.

abstract void
setDisplayShowCustomEnabled(boolean showCustom)

Set whether a custom view should be displayed, if set.

abstract void
setDisplayShowHomeEnabled(boolean showHome)

Set whether to include the application home affordance in the action bar.

abstract void
setDisplayShowTitleEnabled(boolean showTitle)

Set whether an activity title/subtitle should be displayed.

abstract void
setDisplayUseLogoEnabled(boolean useLogo)

Set whether to display the activity logo rather than the activity icon.

void
setElevation(float elevation)

Set the Z-axis elevation of the action bar in pixels.

void
setHideOffset(int offset)

Set the current hide offset of the action bar.

void
setHideOnContentScrollEnabled(boolean hideOnContentScroll)

Enable hiding the action bar on content scroll.

void

Set an alternate description for the Home/Up action, when enabled.

void

Set an alternate description for the Home/Up action, when enabled.

void

Set an alternate drawable to display next to the icon/logo/title when DISPLAY_HOME_AS_UP is enabled.

void

Set an alternate drawable to display next to the icon/logo/title when DISPLAY_HOME_AS_UP is enabled.

void
setHomeButtonEnabled(boolean enabled)

Enable or disable the "home" button in the corner of the action bar.

abstract void

Set the icon to display in the 'home' section of the action bar.

abstract void
setIcon(@DrawableRes int resId)

Set the icon to display in the 'home' section of the action bar.

abstract void

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract void

Set the logo to display in the 'home' section of the action bar.

abstract void
setLogo(@DrawableRes int resId)

Set the logo to display in the 'home' section of the action bar.

abstract void

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

abstract void

This method is deprecated.

Action bar navigation modes are deprecated and not supported by inline toolbar action bars.

void

Set the ActionBar's split background.

void

Set the ActionBar's stacked background.

abstract void
setSubtitle(int resId)

Set the action bar's subtitle.

abstract void

Set the action bar's subtitle.

abstract void
setTitle(@StringRes int resId)

Set the action bar's title.

abstract void

Set the action bar's title.

abstract void

Show the ActionBar if it is not currently showing.

Constants

DISPLAY_HOME_AS_UP

Added in 1.1.0
public static final int DISPLAY_HOME_AS_UP = 4

Display the 'home' element such that it appears as an 'up' affordance. e.g. show an arrow to the left indicating the action that will be taken. Set this flag if selecting the 'home' button in the action bar to return up by a single level in your UI rather than back to the top level or front page.

Setting this option will implicitly enable interaction with the home/up button. See setHomeButtonEnabled.

DISPLAY_SHOW_CUSTOM

Added in 1.1.0
public static final int DISPLAY_SHOW_CUSTOM = 16

Show the custom view if one has been set.

DISPLAY_SHOW_HOME

Added in 1.1.0
public static final int DISPLAY_SHOW_HOME = 2

Show 'home' elements in this action bar, leaving more space for other navigation elements. This includes logo and icon.

DISPLAY_SHOW_TITLE

Added in 1.1.0
public static final int DISPLAY_SHOW_TITLE = 8

Show the activity title and subtitle, if present.

DISPLAY_USE_LOGO

Added in 1.1.0
public static final int DISPLAY_USE_LOGO = 1

Use logo instead of icon if available. This flag will cause appropriate navigation modes to use a wider logo in place of the standard icon.

Added in 1.1.0
Deprecated in 1.1.0
public static final int NAVIGATION_MODE_LIST = 1

List navigation mode. Instead of static title text this mode presents a list menu for navigation within the activity. e.g. this might be presented to the user as a dropdown list.

Added in 1.1.0
Deprecated in 1.1.0
public static final int NAVIGATION_MODE_STANDARD = 0

Standard navigation mode. Consists of either a logo or icon and title text with an optional subtitle. Clicking any of these elements will dispatch onOptionsItemSelected to the host Activity with a MenuItem with item ID android.R.id.home.

Added in 1.1.0
Deprecated in 1.1.0
public static final int NAVIGATION_MODE_TABS = 2

Tab navigation mode. Instead of static title text this mode presents a series of tabs for navigation within the activity.

Public constructors

ActionBar

Added in 1.1.0
public ActionBar()

Public methods

addOnMenuVisibilityListener

Added in 1.1.0
public abstract void addOnMenuVisibilityListener(
    ActionBar.OnMenuVisibilityListener listener
)

Add a listener that will respond to menu visibility change events.

Parameters
ActionBar.OnMenuVisibilityListener listener

The new listener to add

addTab

Added in 1.1.0
Deprecated in 1.1.0
public abstract void addTab(ActionBar.Tab tab)

Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list. If this is the first tab to be added it will become the selected tab.

Parameters
ActionBar.Tab tab

Tab to add

addTab

Added in 1.1.0
Deprecated in 1.1.0
public abstract void addTab(ActionBar.Tab tab, int position)

Add a tab for use in tabbed navigation mode. The tab will be inserted at position. If this is the first tab to be added it will become the selected tab.

Parameters
ActionBar.Tab tab

The tab to add

int position

The new position of the tab

addTab

Added in 1.1.0
Deprecated in 1.1.0
public abstract void addTab(ActionBar.Tab tab, boolean setSelected)

Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.

Parameters
ActionBar.Tab tab

Tab to add

boolean setSelected

True if the added tab should become the selected tab.

addTab

Added in 1.1.0
Deprecated in