public abstract class ActionBar extends Object
Beginning with Android 3.0 (API level 11), the action bar appears at the top of an
activity's window when the activity uses the system's Holo
theme (or one of its descendant themes), which is the default.
You may otherwise add the action bar by calling requestFeature(FEATURE_ACTION_BAR)
or by declaring it in a
custom theme with the windowActionBar
property.
By default, the action bar shows the application icon on the left, followed by the activity title. 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.
From your activity, you can retrieve an instance of ActionBar
by calling getActionBar()
.
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
.
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.
Modifier and Type | Class and Description |
---|---|
static class |
ActionBar.LayoutParams
Per-child layout information associated with action bar custom views.
|
static interface |
ActionBar.OnMenuVisibilityListener
Listener for receiving events when action bar menus are shown or hidden.
|
static interface |
ActionBar.OnNavigationListener
Listener interface for ActionBar navigation events.
|
static class |
ActionBar.Tab
A tab in the action bar.
|
static interface |
ActionBar.TabListener
Callback interface invoked when a tab is focused, unfocused, added, or removed.
|
Modifier and Type | Field and Description |
---|---|
static int |
DISPLAY_HOME_AS_UP
Display the 'home' element such that it appears as an 'up' affordance.
|
static int |
DISPLAY_SHOW_CUSTOM
Show the custom view if one has been set.
|
static int |
DISPLAY_SHOW_HOME
Show 'home' elements in this action bar, leaving more space for other
navigation elements.
|
static int |
DISPLAY_SHOW_TITLE
Show the activity title and subtitle, if present.
|
static int |
DISPLAY_USE_LOGO
Use logo instead of icon if available.
|
static int |
NAVIGATION_MODE_LIST
List navigation mode.
|
static int |
NAVIGATION_MODE_STANDARD
Standard navigation mode.
|
static int |
NAVIGATION_MODE_TABS
Tab navigation mode.
|
Constructor and Description |
---|
ActionBar() |
Modifier and Type | Method and Description |
---|---|
abstract void |
addOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener)
Add a listener that will respond to menu visibility change events.
|
abstract void |
addTab(ActionBar.Tab tab)
Add a tab for use in tabbed navigation mode.
|
abstract void |
addTab(ActionBar.Tab tab,
boolean setSelected)
Add a tab for use in tabbed navigation mode.
|
abstract void |
addTab(ActionBar.Tab tab,
int position)
Add a tab for use in tabbed navigation mode.
|
abstract void |
addTab(ActionBar.Tab tab,
int position,
boolean setSelected)
Add a tab for use in tabbed navigation mode.
|
abstract android.view.View |
getCustomView() |
abstract int |
getDisplayOptions() |
abstract int |
getHeight()
Retrieve the current height of the ActionBar.
|
abstract int |
getNavigationItemCount()
Get the number of navigation items present in the current navigation mode.
|
abstract int |
getNavigationMode()
Returns the current navigation mode.
|
abstract int |
getSelectedNavigationIndex()
Get the position of the selected navigation item in list or tabbed navigation modes.
|
abstract ActionBar.Tab |
getSelectedTab()
Returns the currently selected tab if in tabbed navigation mode and there is at least
one tab present.
|
abstract CharSequence |
getSubtitle()
Returns the current ActionBar subtitle in standard mode.
|
abstract ActionBar.Tab |
getTabAt(int index)
Returns the tab at the specified index.
|
abstract int |
getTabCount()
Returns the number of tabs currently registered with the action bar.
|
android.content.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.
|
abstract boolean |
isShowing() |
abstract ActionBar.Tab |
newTab()
Create and return a new
ActionBar.Tab . |
abstract void |
removeAllTabs()
Remove all tabs from the action bar and deselect the current tab.
|
abstract void |
removeOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener)
Remove a menu visibility listener.
|
abstract void |
removeTab(ActionBar.Tab tab)
Remove a tab from the action bar.
|
abstract void |
removeTabAt(int position)
Remove a tab from the action bar.
|
abstract void |
selectTab(ActionBar.Tab tab)
Select the specified tab.
|
abstract void |
setBackgroundDrawable(android.graphics.drawable.Drawable d)
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 |
setCustomView(android.view.View view)
Set the action bar into custom navigation mode, supplying a view
for custom navigation.
|
abstract void |
setCustomView(android.view.View view,
ActionBar.LayoutParams layoutParams)
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 |
setHomeButtonEnabled(boolean enabled)
Enable or disable the "home" button in the corner of the action bar.
|
abstract void |
setIcon(android.graphics.drawable.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(android.widget.SpinnerAdapter adapter,
ActionBar.OnNavigationListener callback)
Set the adapter and navigation callback for list navigation mode.
|
abstract void |
setLogo(android.graphics.drawable.Drawable logo)
Set the logo to display in the 'home' section of the action bar.
|
abstract void |
setLogo(int resId)
Set the logo to display in the 'home' section of the action bar.
|
abstract void |
setNavigationMode(int mode)
Set the current navigation mode.
|
abstract void |
setSelectedNavigationItem(int position)
Set the selected navigation item in list or tabbed navigation modes.
|
void |
setSplitBackgroundDrawable(android.graphics.drawable.Drawable d)
Set the ActionBar's split background.
|
void |
setStackedBackgroundDrawable(android.graphics.drawable.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.
|
public static final int NAVIGATION_MODE_STANDARD
public static final int NAVIGATION_MODE_LIST
public static final int NAVIGATION_MODE_TABS
public static final int DISPLAY_USE_LOGO
public static final int DISPLAY_SHOW_HOME
public static final int DISPLAY_HOME_AS_UP
Setting this option will implicitly enable interaction with the home/up
button. See setHomeButtonEnabled(boolean)
.
public static final int DISPLAY_SHOW_TITLE
public static final int DISPLAY_SHOW_CUSTOM
public abstract void setCustomView(android.view.View view)
view
- Custom navigation view to place in the ActionBar.public abstract void setCustomView(android.view.View view, ActionBar.LayoutParams layoutParams)
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.setDisplayOptions(int, int)
public abstract void setCustomView(int resId)
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.setDisplayOptions(int, int)
public abstract void setIcon(int resId)
DISPLAY_USE_LOGO
.resId
- Resource ID of a drawable to show as an icon.setDisplayUseLogoEnabled(boolean)
,
setDisplayShowHomeEnabled(boolean)
public abstract void setIcon(android.graphics.drawable.Drawable icon)
DISPLAY_USE_LOGO
.icon
- Drawable to show as an icon.setDisplayUseLogoEnabled(boolean)
,
setDisplayShowHomeEnabled(boolean)
public abstract void setLogo(int resId)
DISPLAY_USE_LOGO
.resId
- Resource ID of a drawable to show as a logo.setDisplayUseLogoEnabled(boolean)
,
setDisplayShowHomeEnabled(boolean)
public abstract void setLogo(android.graphics.drawable.Drawable logo)
DISPLAY_USE_LOGO
.logo
- Drawable to show as a logo.setDisplayUseLogoEnabled(boolean)
,
setDisplayShowHomeEnabled(boolean)
public abstract void setListNavigationCallbacks(android.widget.SpinnerAdapter adapter, ActionBar.OnNavigationListener callback)
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.public abstract void setSelectedNavigationItem(int position)
position
- Position of the item to select.public abstract int getSelectedNavigationIndex()
public abstract int getNavigationItemCount()
public abstract void setTitle(CharSequence title)
DISPLAY_SHOW_TITLE
is set.title
- Title to setsetTitle(int)
,
setDisplayOptions(int, int)
public abstract void setTitle(int resId)
DISPLAY_SHOW_TITLE
is set.resId
- Resource ID of title string to setsetTitle(CharSequence)
,
setDisplayOptions(int, int)
public abstract void setSubtitle(CharSequence subtitle)
DISPLAY_SHOW_TITLE
is set. Set to null to disable the
subtitle entirely.subtitle
- Subtitle to setsetSubtitle(int)
,
setDisplayOptions(int, int)
public abstract void setSubtitle(int resId)
DISPLAY_SHOW_TITLE
is set.resId
- Resource ID of subtitle string to setsetSubtitle(CharSequence)
,
setDisplayOptions(int, int)
public abstract void setDisplayOptions(int options)
setDisplayOptions(int, int)
.options
- A combination of the bits defined by the DISPLAY_ constants
defined in ActionBar.public abstract void setDisplayOptions(int options, int mask)
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.public abstract void setDisplayUseLogoEnabled(boolean useLogo)
To set several display options at once, see the setDisplayOptions methods.
useLogo
- true to use the activity logo, false to use the activity icon.setDisplayOptions(int)
,
setDisplayOptions(int, int)
public abstract void setDisplayShowHomeEnabled(boolean showHome)
To set several display options at once, see the setDisplayOptions methods.
showHome
- true to show home, false otherwise.setDisplayOptions(int)
,
setDisplayOptions(int, int)
public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp)
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.setDisplayOptions(int)
,
setDisplayOptions(int, int)
public abstract void setDisplayShowTitleEnabled(boolean showTitle)
To set several display options at once, see the setDisplayOptions methods.
showTitle
- true to display a title/subtitle if present.setDisplayOptions(int)
,
setDisplayOptions(int, int)
public abstract void setDisplayShowCustomEnabled(boolean showCustom)
To set several display options at once, see the setDisplayOptions methods.
showCustom
- true if the currently set custom view should be displayed, false otherwise.setDisplayOptions(int)
,
setDisplayOptions(int, int)
public abstract void setBackgroundDrawable(android.graphics.drawable.Drawable d)
d
- Background drawablesetStackedBackgroundDrawable(Drawable)
,
setSplitBackgroundDrawable(Drawable)
public void setStackedBackgroundDrawable(android.graphics.drawable.Drawable d)
d
- Background drawable for the stacked rowpublic void setSplitBackgroundDrawable(android.graphics.drawable.Drawable d)
You can enable split action bar with R.attr.uiOptions
d
- Background drawable for the split barpublic abstract android.view.View getCustomView()
public abstract CharSequence getTitle()
getNavigationMode()
would not return
NAVIGATION_MODE_STANDARD
.public abstract CharSequence getSubtitle()
getNavigationMode()
would not return
NAVIGATION_MODE_STANDARD
.public abstract int getNavigationMode()
public abstract void setNavigationMode(int mode)
mode
- The new mode to set.NAVIGATION_MODE_STANDARD
,
NAVIGATION_MODE_LIST
,
NAVIGATION_MODE_TABS
public abstract int getDisplayOptions()
public abstract ActionBar.Tab newTab()
ActionBar.Tab
.
This tab will not be included in the action bar until it is added.
Very often tabs will be used to switch between Fragment
objects. Here is a typical implementation of such tabs:
addTab(Tab)
public abstract void addTab(ActionBar.Tab tab)
tab
- Tab to addpublic abstract void addTab(ActionBar.Tab tab, boolean setSelected)
tab
- Tab to addsetSelected
- True if the added tab should become the selected tab.public abstract void addTab(ActionBar.Tab tab, int position)
position
. If this is the first tab to be added it will become
the selected tab.tab
- The tab to addposition
- The new position of the tabpublic abstract void addTab(ActionBar.Tab tab, int position, boolean setSelected)
position
.tab
- The tab to addposition
- The new position of the tabsetSelected
- True if the added tab should become the selected tab.public abstract void removeTab(ActionBar.Tab tab)
tab
- The tab to removepublic abstract void removeTabAt(int position)
position
- Position of the tab to removepublic abstract void removeAllTabs()
public abstract void selectTab(ActionBar.Tab tab)
Note: If you want to select by index, use setSelectedNavigationItem(int)
.
tab
- Tab to selectpublic abstract ActionBar.Tab getSelectedTab()
public abstract ActionBar.Tab getTabAt(int index)
index
- Index value in the range 0-getpublic abstract int getTabCount()
public abstract int getHeight()
public abstract void show()
Window#FEATURE_ACTION_BAR_OVERLAY
it will resize application
content to fit the new space available.public abstract void hide()
Window#FEATURE_ACTION_BAR_OVERLAY
it will resize application
content to fit the new space available.public abstract boolean isShowing()
true
if the ActionBar is showing, false
otherwise.public abstract void addOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener)
listener
- The new listener to addpublic abstract void removeOnMenuVisibilityListener(ActionBar.OnMenuVisibilityListener listener)
listener
- A listener to remove that was previously addedpublic void setHomeButtonEnabled(boolean enabled)
This defaults to true for packages targeting < API 14. For packages targeting API 14 or greater, the application should call this method to enable interaction with the home/up affordance.
Setting the DISPLAY_HOME_AS_UP
display option will automatically enable
the home button.
enabled
- true to enable the home button, false to disable the home button.public android.content.Context getThemedContext()
Context
with an appropriate theme for creating views that
will appear in the action bar. If you are inflating or instantiating custom views
that will appear in an action bar, you should use the Context returned by this method.
(This includes adapters used for list navigation mode.)
This will ensure that views contrast properly against the action bar.Copyright © 2011–2014. All rights reserved.