Google は、黒人コミュニティに対する人種平等の促進に取り組んでいます。取り組みを見る

ActionBar

abstract class ActionBar
kotlin.Any
   ↳ 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 R.style#Theme_AppCompat theme (or one of its descendant themes). You may otherwise add the action bar by calling or by declaring it in a custom theme with the R.styleable#AppCompatTheme_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 R.styleable#AppCompatTheme_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()}.

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 classes
open

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

abstract

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

abstract

Listener interface for ActionBar navigation events.

abstract

A tab in the action bar.

abstract

Callback interface invoked when a tab is focused, unfocused, added, or removed.

Constants
static Int

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

static Int

Show the custom view if one has been set.

static Int

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

static Int

Show the activity title and subtitle, if present.

static Int

Use logo instead of icon if available.

static Int

List navigation mode.

static Int

Standard navigation mode.

static Int

Tab navigation mode.

Public constructors

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

Public methods
abstract Unit

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

abstract Unit

Add a tab for use in tabbed navigation mode.

abstract Unit
addTab(tab: ActionBar.Tab!, setSelected: Boolean)

Add a tab for use in tabbed navigation mode.

abstract Unit
addTab(tab: ActionBar.Tab!, position: Int)

Add a tab for use in tabbed navigation mode.

abstract Unit
addTab(tab: ActionBar.Tab!, position: Int, setSelected: Boolean)

Add a tab for use in tabbed navigation mode.

abstract View!

abstract Int

open Float

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

abstract Int

Retrieve the current height of the ActionBar.

open Int

Return the current vertical offset of the action bar.

abstract Int

Get the number of navigation items present in the current navigation mode.

abstract Int

Returns the current navigation mode.

abstract Int

Get the position of the selected navigation item in list or tabbed navigation modes.

abstract ActionBar.Tab?

Returns the currently selected tab if in tabbed navigation mode and there is at least one tab present.

abstract CharSequence?

Returns the current ActionBar subtitle in standard mode.

abstract ActionBar.Tab!
getTabAt(index: Int)

Returns the tab at the specified index.

abstract Int

Returns the number of tabs currently registered with the action bar.

open Context!

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

abstract CharSequence?

Returns the current ActionBar title in standard mode.

abstract Unit

Hide the ActionBar if it is currently showing.

open Boolean

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

abstract Boolean

abstract ActionBar.Tab!

Create and return a new Tab.

abstract Unit

Remove all tabs from the action bar and deselect the current tab.

abstract Unit

Remove a menu visibility listener.

abstract Unit

Remove a tab from the action bar.

abstract Unit
removeTabAt(position: Int)

Remove a tab from the action bar.

abstract Unit

Select the specified tab.

abstract Unit

Set the ActionBar's background.

abstract Unit

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

abstract Unit
setCustomView(view: View!, layoutParams: ActionBar.LayoutParams!)

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

abstract Unit

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

abstract Unit

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

abstract Unit

Set display options.

abstract Unit
setDisplayOptions(options: Int, mask: Int)

Set selected display options.

abstract Unit

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

abstract Unit

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

abstract Unit

Set whether an activity title/subtitle should be displayed.

abstract Unit

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

open Unit
setElevation(elevation: Float)

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

open Unit
setHideOffset(offset: Int)

Set the current hide offset of the action bar.

open Unit
setHideOnContentScrollEnabled(hideOnContentScroll: Boolean)

Enable hiding the action bar on content scroll.

open Unit

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

open Unit

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

open Unit
setHomeAsUpIndicator(@Nullable indicator: Drawable?)

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

open Unit
setHomeAsUpIndicator(@DrawableRes resId: Int)

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

open Unit

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

abstract Unit
setIcon(@DrawableRes resId: Int)

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

abstract Unit
setIcon(icon: Drawable!)

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

abstract Unit

Set the adapter and navigation callback for list navigation mode.

abstract Unit
setLogo(@DrawableRes resId: Int)

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

abstract Unit
setLogo(: Drawable!)

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

abstract Unit

Set the current navigation mode.

abstract Unit

Set the selected navigation item in list or tabbed navigation modes.

open Unit

Set the ActionBar's split background.

open Unit

Set the ActionBar's stacked background.

abstract Unit

Set the action bar's subtitle.

abstract Unit
setSubtitle(resId: Int)

Set the action bar's subtitle.

abstract Unit

Set the action bar's title.

abstract Unit
setTitle(@StringRes resId: Int)

Set the action bar's title.

abstract Unit

Show the ActionBar if it is not currently showing.

Constants

DISPLAY_HOME_AS_UP

static val DISPLAY_HOME_AS_UP: 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. 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).

Value: android.app.ActionBar.DISPLAY_HOME_AS_UP

DISPLAY_SHOW_CUSTOM

static val DISPLAY_SHOW_CUSTOM: Int

Show the custom view if one has been set.

Value: android.app.ActionBar.DISPLAY_SHOW_CUSTOM

DISPLAY_SHOW_HOME

static val DISPLAY_SHOW_HOME: Int

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

Value: android.app.ActionBar.DISPLAY_SHOW_HOME

DISPLAY_SHOW_TITLE

static val DISPLAY_SHOW_TITLE: Int

Show the activity title and subtitle, if present.

Value: android.app.ActionBar.DISPLAY_SHOW_TITLE
static val DISPLAY_USE_LOGO: Int

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.

Value: android.app.ActionBar.DISPLAY_USE_LOGO
static val NAVIGATION_MODE_LIST: Int

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

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.

Value: 1
static val NAVIGATION_MODE_STANDARD: Int

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

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.

Value: 0
static val NAVIGATION_MODE_TABS: Int

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

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

Value: 2

Public constructors

<init>

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 R.style#Theme_AppCompat theme (or one of its descendant themes). You may otherwise add the action bar by calling or by declaring it in a custom theme with the R.styleable#AppCompatTheme_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 R.styleable#AppCompatTheme_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()}.

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.

Public methods

addOnMenuVisibilityListener

abstract fun addOnMenuVisibilityListener(listener: ActionBar.OnMenuVisibilityListener!): Unit

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

Parameters
listener ActionBar.OnMenuVisibilityListener!: The new listener to add

addTab

abstract fun addTab(tab: ActionBar.Tab!): Unit

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

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
tab ActionBar.Tab!: Tab to add

addTab

abstract fun addTab(
    tab: ActionBar.Tab!,
    setSelected: Boolean
): Unit

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

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

Parameters
tab ActionBar.Tab!: Tab to add
setSelected Boolean: True if the added tab should become the selected tab.

addTab

abstract fun addTab(
    tab: ActionBar.Tab!,
    position: Int
): Unit

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

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
tab ActionBar.Tab!: The tab to add
position Int: The new position of the tab

addTab

abstract fun addTab(
    tab: ActionBar.Tab!,
    position: Int,
    setSelected: Boolean
): Unit

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

Add a tab for use in tabbed navigation mode. The tab will be inserted at position.

Parameters
tab ActionBar.Tab!: The tab to add
position Int: The new position of the tab
setSelected Boolean: True if the added tab should become the selected tab.

getCustomView

abstract fun getCustomView(): View!
Return
View! The current custom view.

getDisplayOptions

abstract fun getDisplayOptions(): Int
Return
Int The current set of display options.

getElevation

open fun getElevation(): Float

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

The action bar's elevation is the distance it is placed from its parent surface. Higher values are closer to the user.

Return
Float Elevation value in pixels

getHeight

abstract fun getHeight(): Int

Retrieve the current height of the ActionBar.

Return
Int The ActionBar's height

getHideOffset

open fun getHideOffset(): Int

Return the current vertical offset of the action bar.

The action bar's current hide offset is the distance that the action bar is currently scrolled offscreen in pixels. The valid range is 0 (fully visible) to the action bar's current measured height (fully invisible).

Return
Int The action bar's offset toward its fully hidden state in pixels

getNavigationItemCount

abstract fun getNavigationItemCount(): Int

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

Get the number of navigation items present in the current navigation mode.

Return
Int Number of navigation items.

getNavigationMode

abstract fun getNavigationMode(): Int

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

Returns the current navigation mode. The result will be one of:

Return
Int The current navigation mode.

getSelectedNavigationIndex

abstract fun getSelectedNavigationIndex(): Int

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

Get the position of the selected navigation item in list or tabbed navigation modes.

Return
Int Position of the selected item.

getSelectedTab

@Nullable abstract fun getSelectedTab(): ActionBar.Tab?

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

Returns the currently selected tab if in tabbed navigation mode and there is at least one tab present.

Return
ActionBar.Tab? The currently selected tab or null

getSubtitle

@Nullable abstract fun getSubtitle(): CharSequence?

Returns the current ActionBar subtitle in standard mode. Returns null if getNavigationMode() would not return NAVIGATION_MODE_STANDARD.

Return
CharSequence? The current ActionBar subtitle or null.

getTabAt

abstract fun getTabAt(index: Int): ActionBar.Tab!

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

Returns the tab at the specified index.

Parameters
index Int: Index value in the range 0-get
Return
ActionBar.Tab!

getTabCount

abstract fun getTabCount(): Int

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

Returns the number of tabs currently registered with the action bar.

Return
Int Tab count

getThemedContext

open fun getThemedContext(): Context!

Returns a 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.

Return
Context! A themed Context for creating views

getTitle

@Nullable abstract fun getTitle(): CharSequence?

Returns the current ActionBar title in standard mode. Returns null if getNavigationMode() would not return NAVIGATION_MODE_STANDARD.

Return
CharSequence? The current ActionBar title or null.

hide

abstract fun hide(): Unit

Hide the ActionBar if it is currently showing. If the window hosting the ActionBar does not have the feature Window#FEATURE_ACTION_BAR_OVERLAY it will resize application content to fit the new space available.

Instead of calling this function directly, you can also cause an ActionBar using the overlay feature to hide through View.SYSTEM_UI_FLAG_FULLSCREEN. Hiding the ActionBar through this system UI flag allows you to more seamlessly hide it in conjunction with other screen decorations.

isHideOnContentScrollEnabled