Android 开发之官方文档ActionBar学习记录

今天学习用到了actionbar,就试着去翻译了下官方文档来学习,英语水平有限

ActionBar

extends Objecthtml

java.lang.Objectjava

android.app.ActionBarandroid

Class Overview


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的。

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.

有关如何去使用操做栏的更多信息,包括如何去添加一个操做项,导航模型或者更多其余的,请阅读Action bar 开发者向导

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

公共构造方法

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

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

相关文章
相关标签/搜索