ActionBar

public abstract class ActionBar
extends Object

java.lang.Object
   ↳ androidx.appcompat.app.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 AppCompatActivity.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.

Developer Guides

For information about how to use the action bar, including how to add action items, navigation modes and more, read the Action Bar developer guide.

Summary

Nested classes

class ActionBar.LayoutParams

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

interface ActionBar.OnMenuVisibilityListener

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

interface ActionBar.OnNavigationListener

This interface is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.  

class ActionBar.Tab

This class is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.  

interface ActionBar.TabListener

This interface is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.  

Constants

int DISPLAY_HOME_AS_UP

Display the 'home' element such that it appears as an 'up' affordance.

int DISPLAY_SHOW_CUSTOM

Show the custom view if one has been set.

int DISPLAY_SHOW_HOME

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

int DISPLAY_SHOW_TITLE

Show the activity title and subtitle, if present.

int DISPLAY_USE_LOGO

Use logo instead of icon if available.

int NAVIGATION_MODE_LIST

This constant is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

int NAVIGATION_MODE_STANDARD

This constant is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

int NAVIGATION_MODE_TABS

This constant is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Public constructors

ActionBar()

Public methods

abstract void addOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener)

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

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. Consider using other common navigation patterns instead.

abstract void addTab(ActionBar.Tab tab)

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

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. Consider using other common navigation patterns instead.

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. Consider using other common navigation patterns instead.

abstract View getCustomView()
abstract int getDisplayOptions()
float getElevation()

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

abstract int getHeight()

Retrieve the current height of the ActionBar.

int getHideOffset()

Return the current vertical offset of the action bar.

abstract int getNavigationItemCount()

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

abstract int getNavigationMode()

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

abstract int getSelectedNavigationIndex()

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

abstract ActionBar.Tab getSelectedTab()

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

abstract CharSequence getSubtitle()

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. Consider using other common navigation patterns instead.

abstract int getTabCount()

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

Context getThemedContext()

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

abstract CharSequence getTitle()

Returns the current ActionBar title in standard mode.

abstract void hide()

Hide the ActionBar if it is currently showing.

boolean isHideOnContentScrollEnabled()

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

abstract boolean isShowing()
abstract ActionBar.Tab newTab()

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

abstract void removeAllTabs()

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

abstract void removeOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener)

Remove a menu visibility listener.

abstract void removeTab(ActionBar.Tab tab)

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

abstract void removeTabAt(int position)

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

abstract void selectTab(ActionBar.Tab tab)

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

abstract void setBackgroundDrawable(Drawable d)

Set the ActionBar's background.

abstract void setCustomView(View view)

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

abstract void setCustomView(View view, ActionBar.LayoutParams layoutParams)

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

abstract void setCustomView(int resId)

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, int mask)

Set selected display options.

abstract void setDisplayOptions(int options)

Set 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 setHomeActionContentDescription(CharSequence description)

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

void setHomeActionContentDescription(int resId)

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

void setHomeAsUpIndicator(int resId)

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

void setHomeAsUpIndicator(Drawable indicator)

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 setIcon(Drawable icon)

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

abstract void setIcon(int resId)

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

abstract void setListNavigationCallbacks(SpinnerAdapter adapter, ActionBar.OnNavigationListener callback)

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

abstract void setLogo(int resId)

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

abstract void setLogo(Drawable logo)

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

abstract void setNavigationMode(int mode)

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

abstract void setSelectedNavigationItem(int position)

This method is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.

void setSplitBackgroundDrawable(Drawable d)

Set the ActionBar's split background.

void setStackedBackgroundDrawable(Drawable d)

Set the ActionBar's stacked background.

abstract void setSubtitle(CharSequence subtitle)

Set the action bar's subtitle.

abstract void setSubtitle(int resId)

Set the action bar's subtitle.

abstract void setTitle(CharSequence title)

Set the action bar's title.

abstract void setTitle(int resId)

Set the action bar's title.

abstract void show()

Show the ActionBar if it is not currently showing.

Inherited methods

Constants

DISPLAY_HOME_AS_UP

public static final int DISPLAY_HOME_AS_UP

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(boolean).

Constant Value: 4 (0x00000004)

DISPLAY_SHOW_CUSTOM

public static final int DISPLAY_SHOW_CUSTOM

Show the custom view if one has been set.

Constant Value: 16 (0x00000010)

DISPLAY_SHOW_HOME

public static final int DISPLAY_SHOW_HOME

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

Constant Value: 2 (0x00000002)