extends Objecthtml
java.lang.Objectjava
android.app.ActionBarandroid
A primary toolbar within the activity that may display the activity title, application-level navigation affordances, and other interactive items.chrome
在activity中的一個主要的工具欄,它能夠展現這個activity的標題,應用程序級的導航功能和其餘的交互性元素。express
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.api
ActionBar在android 3.0被引入,在activity使用系統的Holo主題(或者集成該主題的後代主題)時,操做欄出如今activity窗口的頂部,這是默認的配置。不然你能夠經過調用requestFeature(FEATURE_ACTION_BAR)
或者在一個自定義主題中用windowActionBar屬性去增長操做欄(action bar)。
app
Beginning with Android L (API level 21), 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.ide
從android L版本(API level 21)開始。應用程序佈局中的操做欄能夠用任意的Toolbar widget (工具欄小部件)去描述。應用程序告訴acitity工具欄是該做爲這個activity的操做欄進行處理。擁有actionbar特性的activity將使用一個NoActionBar
主題提供支持。設置windowActionBar屬性爲false值或者不請求這個窗口特性。
函數
By adjusting(調整) the window features requested by the theme and the layouts used for an Activity's content view, an app can use the standard system action bar on older platform releases and the newer inline toolbars on newer platform releases. The ActionBar
object obtained from the Activity can be used to control either configuration transparently.工具
activity的文本視圖增長這個窗口特性可經過主題和佈局文件去調整,在老的平臺發佈應用程序時,應用程序可使用標準的系統操做欄,在新的應用平臺發佈應用程序,應用程序可使用最新的內聯工具欄。ActionBar
對象從activity 中得到,該對象能夠被使用去控制或者配置一些特性。
When using the Holo themes 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.
當使用這Holo主題時,操做欄在左邊展現應用程序的圖標,接下來是activity 的標題。若是你的activity有一個可選的菜單,你能夠直接從操做欄選擇一個菜單項做爲操做項直接進入。
你也能夠修改操做欄的各類特性甚至徹底刪除它。
When using the Material themes (default in API 21 or newer) 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.
當導航按鈕(原名「home」)使用Material 主題(在api21或者以上被定義)時,將佔據先前應用程序的圖標的空間位置。應用程序但願在操做欄和其餘應用程序的網格或者他們標準的標題文本中使用有logo的地方去突出的展現一個品牌效果,是該使用本身定義的顏色行爲在操做欄中。
From your activity, you can retrieve an instance of ActionBar
by calling getActionBar()
.
在activity中,你能夠經過吊桶getActionBar()方法得到一個actionBar的實例對象。
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 forActionBar
.
在某些狀況下,使用一個ActionMode可使
操做欄能夠被其它能共使用上下文的操做欄覆蓋。例如,當用戶在不得activity中選擇一個或者更多的項,你能夠開啓一個提供選擇指定項的操做模型做爲一個用戶界面元素,該元素零時取代操做欄。即便這UI可能佔據一些內存空間,可是這個ActionMode API 是獨特的,獨立於其餘的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.
有關如何去使用操做欄的更多信息,包括如何去添加一個操做項,導航模型或者更多其餘的,請閱讀Action bar 開發者嚮導
概要
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 was deprecated in API level 21. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.
該接口在AIP 21被棄用,操做欄導航面板被啓用,不被內聯的工具欄 操做欄支持。考慮使用其餘的公共導航模式代替
class
ActionBar.Tab
This class was deprecated in API level 21. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patternsinstead.
interface
ActionBar.TabListener
This interface was deprecated in API level 21. 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.
展現一個‘home‘元素以便提供一個’up‘的功能。
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.
在操做欄顯示’home‘元素,爲其餘導航元素留下更多的空間
int
DISPLAY_SHOW_TITLE
Show the activity title and subtitle, if present.
若是acivity的標題和子標題存在,則展現出來。
int
DISPLAY_USE_LOGO
Use logo instead of icon if available.
若是可用使用logo去替換圖標
int
NAVIGATION_MODE_LIST
This constant was deprecated in API level 21. 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 was deprecated in API level 21. 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 was deprecated in API level 21. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.
Public Constructors
公共構造方法
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 was deprecated in API level 21. 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 was deprecated in API level 21. 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 was deprecated in API level 21. 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 was deprecated in API level 21. 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.
以像素點爲單位獲得操做欄Z軸的值
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 was deprecated in API level 21. 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 was deprecated in API level 21. 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 was deprecated in API level 21. 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 was deprecated in API level 21. 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 was deprecated in API level 21. 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 was deprecated in API level 21. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead.
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 was deprecated in API level 21. 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 was deprecated in API level 21. 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 was deprecated in API level 21. 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 was deprecated in API level 21. 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 was deprecated in API level 21. 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(int resId)
Set the action bar into custom navigation mode, supplying a view for custom navigation.
(後面繼續翻譯)
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
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(Drawable indicator)
Set an alternate drawable to display next to the icon/logo/title when DISPLAY_HOME_AS_UP
is 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
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 was deprecated in API level 21. 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 was deprecated in API level 21. 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 was deprecated in API level 21. 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(int resId)
Set the action bar's subtitle.
abstract void
setSubtitle(CharSequence subtitle)
Set the action bar's subtitle.
abstract void
setTitle(int resId)
Set the action bar's title.
abstract void
setTitle(CharSequence title)
Set the action bar's title.
abstract void
show()
Show the ActionBar if it is not currently showing.