java.lang.Object | |
↳ | android.app.ActionBar |
This is the public interface to the contextual ActionBar. The ActionBar acts as a replacement for the title bar in Activities. It provides facilities for creating toolbar actions as well as methods of navigating around an application.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ActionBar.LayoutParams | Per-child layout information associated with action bar custom views. | ||||||||||
ActionBar.OnMenuVisibilityListener | Listener for receiving events when action bar menus are shown or hidden. | ||||||||||
ActionBar.OnNavigationListener | Listener interface for ActionBar navigation events. | ||||||||||
ActionBar.Tab | A tab in the action bar. | ||||||||||
ActionBar.TabListener | Callback interface invoked when a tab is focused, unfocused, added, or removed. |
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 | List navigation mode. | |||||||||
int | NAVIGATION_MODE_STANDARD | Standard navigation mode. | |||||||||
int | NAVIGATION_MODE_TABS | Tab navigation mode. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Add a listener that will respond to menu visibility change events.
| |||||||||||
Add a tab for use in tabbed navigation mode.
| |||||||||||
Add a tab for use in tabbed navigation mode.
| |||||||||||
Add a tab for use in tabbed navigation mode.
| |||||||||||
Add a tab for use in tabbed navigation mode.
| |||||||||||
Retrieve the current height of the ActionBar.
| |||||||||||
Get the number of navigation items present in the current navigation mode.
| |||||||||||
Returns the current navigation mode.
| |||||||||||
Get the position of the selected navigation item in list or tabbed navigation modes.
| |||||||||||
Returns the currently selected tab if in tabbed navigation mode and there is at least
one tab present.
| |||||||||||
Returns the current ActionBar subtitle in standard mode.
| |||||||||||
Returns the tab at the specified index.
| |||||||||||
Returns the number of tabs currently registered with the action bar.
| |||||||||||
Returns the current ActionBar title in standard mode.
| |||||||||||
Hide the ActionBar if it is not currently showing.
| |||||||||||
Create and return a new
ActionBar.Tab . | |||||||||||
Remove all tabs from the action bar and deselect the current tab.
| |||||||||||
Remove a menu visibility listener.
| |||||||||||
Remove a tab from the action bar.
| |||||||||||
Remove a tab from the action bar.
| |||||||||||
Select the specified tab.
| |||||||||||
Set the ActionBar's background.
| |||||||||||
Set the action bar into custom navigation mode, supplying a view
for custom navigation.
| |||||||||||
Set the action bar into custom navigation mode, supplying a view
for custom navigation.
| |||||||||||
Set the action bar into custom navigation mode, supplying a view
for custom navigation.
| |||||||||||
Set whether home should be displayed as an "up" affordance.
| |||||||||||
Set selected display options.
| |||||||||||
Set display options.
| |||||||||||
Set whether a custom view should be displayed, if set.
| |||||||||||
Set whether to include the application home affordance in the action bar.
| |||||||||||
Set whether an activity title/subtitle should be displayed.
| |||||||||||
Set whether to display the activity logo rather than the activity icon.
| |||||||||||
Set the adapter and navigation callback for list navigation mode.
| |||||||||||
Set the current navigation mode.
| |||||||||||
Set the selected navigation item in list or tabbed navigation modes.
| |||||||||||
Set the action bar's subtitle.
| |||||||||||
Set the action bar's subtitle.
| |||||||||||
Set the action bar's title.
| |||||||||||
Set the action bar's title.
| |||||||||||
Show the ActionBar if it is not currently showing.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
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.
Show the custom view if one has been set.
Show 'home' elements in this action bar, leaving more space for other navigation elements. This includes logo and icon.
Show the activity title and subtitle, if present.
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.
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.
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.
Tab navigation mode. Instead of static title text this mode presents a series of tabs for navigation within the activity.
Add a listener that will respond to menu visibility change events.
listener | The new listener to add |
---|
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.
tab | Tab to add |
---|
Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
tab | Tab to add |
---|---|
setSelected | True if the added tab should become the selected tab. |
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.
tab | The tab to add |
---|---|
position | The new position of the tab |
Add a tab for use in tabbed navigation mode. The tab will be insterted at
position
.
tab | The tab to add |
---|---|
position | The new position of the tab |
setSelected | True if the added tab should become the selected tab. |
Retrieve the current height of the ActionBar.
Get the number of navigation items present in the current navigation mode.
Returns the current navigation mode. The result will be one of:
Get the position of the selected navigation item in list or tabbed navigation modes.
Returns the currently selected tab if in tabbed navigation mode and there is at least one tab present.
Returns the current ActionBar subtitle in standard mode.
Returns null if getNavigationMode()
would not return
NAVIGATION_MODE_STANDARD
.
Returns the tab at the specified index.
index | Index value in the range 0-get |
---|
Returns the number of tabs currently registered with the action bar.
Returns the current ActionBar title in standard mode.
Returns null if getNavigationMode()
would not return
NAVIGATION_MODE_STANDARD
.
Hide the ActionBar if it is not currently showing.
If the window hosting the ActionBar does not have the feature
FEATURE_ACTION_BAR_OVERLAY
it will resize application
content to fit the new space available.
true
if the ActionBar is showing, false
otherwise.
Create and return a new ActionBar.Tab
.
This tab will not be included in the action bar until it is added.
Remove all tabs from the action bar and deselect the current tab.
Remove a menu visibility listener. This listener will no longer receive menu visibility change events.
listener | A listener to remove that was previously added |
---|
Remove a tab from the action bar. If the removed tab was selected it will be deselected and another tab will be selected if present.
tab | The tab to remove |
---|
Remove a tab from the action bar. If the removed tab was selected it will be deselected and another tab will be selected if present.
position | Position of the tab to remove |
---|
Select the specified tab. If it is not a child of this action bar it will be added.
Note: If you want to select by index, use setSelectedNavigationItem(int)
.
tab | Tab to select |
---|
Set the ActionBar's background.
d | Background drawable |
---|
Set the action bar into custom navigation mode, supplying a view for custom navigation.
Custom navigation views appear between the application icon and any action buttons and may use any space available there. Common use cases for custom navigation views might include an auto-suggesting address bar for a browser or other navigation mechanisms that do not translate well to provided navigation modes.
The display option DISPLAY_SHOW_CUSTOM
must be set for
the custom view to be displayed.
resId | Resource ID of a layout to inflate into the ActionBar. |
---|
Set the action bar into custom navigation mode, supplying a view for custom navigation. Custom navigation views appear between the application icon and any action buttons and may use any space available there. Common use cases for custom navigation views might include an auto-suggesting address bar for a browser or other navigation mechanisms that do not translate well to provided navigation modes.
view | Custom navigation view to place in the ActionBar. |
---|
Set the action bar into custom navigation mode, supplying a view for custom navigation.
Custom navigation views appear between the application icon and any action buttons and may use any space available there. Common use cases for custom navigation views might include an auto-suggesting address bar for a browser or other navigation mechanisms that do not translate well to provided navigation modes.
The display option DISPLAY_SHOW_CUSTOM
must be set for
the custom view to be displayed.
view | Custom navigation view to place in the ActionBar. |
---|---|
layoutParams | How this custom view should layout in the bar. |
Set whether home should be displayed as an "up" affordance. Set this to true if selecting "home" returns up by a single level in your UI rather than back to the top level or front page.
To set several display options at once, see the setDisplayOptions methods.
showHomeAsUp | true to show the user that selecting home will return one level up rather than to the top level of the app. |
---|
Set selected display options. Only the options specified by mask will be changed.
To change all display option bits at once, see setDisplayOptions(int)
.
Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
DISPLAY_SHOW_HOME
option.
setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO)
will enable DISPLAY_SHOW_HOME
and disable DISPLAY_USE_LOGO
.
options | A combination of the bits defined by the DISPLAY_ constants defined in ActionBar. |
---|---|
mask | A bit mask declaring which display options should be changed. |
Set display options. This changes all display option bits at once. To change
a limited subset of display options, see setDisplayOptions(int, int)
.
options | A combination of the bits defined by the DISPLAY_ constants defined in ActionBar. |
---|
Set whether a custom view should be displayed, if set.
To set several display options at once, see the setDisplayOptions methods.
showCustom | true if the currently set custom view should be displayed, false otherwise. |
---|
Set whether to include the application home affordance in the action bar. Home is presented as either an activity icon or logo.
To set several display options at once, see the setDisplayOptions methods.
showHome | true to show home, false otherwise. |
---|
Set whether an activity title/subtitle should be displayed.
To set several display options at once, see the setDisplayOptions methods.
showTitle | true to display a title/subtitle if present. |
---|
Set whether to display the activity logo rather than the activity icon. A logo is often a wider, more detailed image.
To set several display options at once, see the setDisplayOptions methods.
useLogo | true to use the activity logo, false to use the activity icon. |
---|
Set the adapter and navigation callback for list navigation mode. The supplied adapter will provide views for the expanded list as well as the currently selected item. (These may be displayed differently.) The supplied OnNavigationListener will alert the application when the user changes the current list selection.
adapter | An adapter that will provide views both to display the current navigation selection and populate views within the dropdown navigation menu. |
---|---|
callback | An OnNavigationListener that will receive events when the user selects a navigation item. |
Set the current navigation mode.
mode | The new mode to set. |
---|
Set the selected navigation item in list or tabbed navigation modes.
position | Position of the item to select. |
---|
Set the action bar's subtitle. This will only be displayed if
DISPLAY_SHOW_TITLE
is set.
resId | Resource ID of subtitle string to set |
---|
Set the action bar's subtitle. This will only be displayed if
DISPLAY_SHOW_TITLE
is set. Set to null to disable the
subtitle entirely.
subtitle | Subtitle to set |
---|
Set the action bar's title. This will only be displayed if
DISPLAY_SHOW_TITLE
is set.
title | Title to set |
---|
Set the action bar's title. This will only be displayed if
DISPLAY_SHOW_TITLE
is set.
resId | Resource ID of title string to set |
---|
Show the ActionBar if it is not currently showing.
If the window hosting the ActionBar does not have the feature
FEATURE_ACTION_BAR_OVERLAY
it will resize application
content to fit the new space available.