ActionBar - API

来源:互联网 发布:淘宝女装店哪个好 编辑:程序博客网 时间:2024/04/30 16:50

1、ActionBar:一个在Activity顶部显示Activity标题、导航模式和其他交互选项的功能。


2、ActionBar的使用条件API level >=11(Android 3.0),Android自己的支持library、大神的开源支持library


3、什么时候显示ActionBar:
①使用系统Holo主题(application/Activity)、
②调用requestFeature(FEATURE_ACTION_BAR)、

③在自定义的主题中声明windowActionBar属性


4、默认情况下应用的icon显示在ActionBar的左边,紧接着是ACtivity的标题。如果Activity有选项菜单的话,你可以使选择的项目(菜单项目)通过ActionBar作为“action items(动作项)”直接访问。你可以更改ActionBar的许多特性或完全移除ActionBar。


5、获取ActionBar的实例:可以通过getActionBar()获取ActionBar()的实例


6、有些情况下,ActionBar被另一个ActionBar覆盖而使一些上下文有关Action可以使用,这种可通过ActionMode实现。例如当选择一个或者多个的时候,你可一激活一种专门处理选择的ActionMode,UI临时更换到这个ActionBar。尽管UI占据相同的地方,但是这些ActionMode APIs对于ActionBar是截然不同的和相互独立的。


7、嵌套类或接口:

class - ActionBar.LayoutParams 与ActionBar自定义的视图关联的每一个子布局的信息
interface - ActionBar.OnMenuVisibilityListener 监听接收到ActionBar菜单显示和隐藏的事件
interface - ActionBar.OnNavigationListener 监听ActionBar导航事件
class - ActionBar.Tab   ActionBar中选项卡
interface - ActionBar.TabListener 回调接口处理当一个tab有焦点,没有焦点,添加,删除


8、常量:

DISPLAY_HOME_AS_UP:
①显示ActionBar "home"的组成使这个"home"的组成显示为"向上(UP)"的意思。
②例如显示一个向左的箭头表明选中这个Action。
③如果需要在ActionBar里使用“home”来返回上一级而不是返回到最开始的界面,就设置这个域。
④设置此选项将隐式启用Home/UP按钮的交互。
⑤如果DISPLAY_HOME_AS_UP已经启用,则已经隐式启用Home/UP按钮的交互。但是禁止DISPLAY_HOME_AS_UP时,并不意味着隐式进制HOME/UP按钮的交互,若须禁止,须调用setHomeButtonEnabled(false)。
⑥参看setHomeButtonEnabled(boolean).
⑦参看setDisplayOptions(int)/setDisplayOptions(int, int)
DISPLAY_SHOW_CUSTOM:
①如果设置了自已view,则该常量设定显示自定义ActionBar
②参看setCustomView(view)/setDisplayOptions(int)/setDisplayOptions(int,int)
DISPLAY_SHOW_HOME:
①显示HOME组成。如果隐藏则可空出空间给其他导航Action
②参看setCustomView(view)/setDisplayOptions(int)/setDisplayOptions(int,int)
DISPLAY_SHOW_TITLE:
①如果有的话显示标题和副标题
②参看setTitle(CharSequence)/setTitle(int)/setSubtitle(CharSequence)/setSubtitle(int)
③参看setDisplayOptions(int)/setDiaplayOptions(int,int)
DISPLAY_USE_LOGO:
①如果可以的话,使用LOGO(商业图标,不一定很小)替换ICON(很小的图标在左上角,软件的启动icon)
②这个标识将引起适当的导航模式(3中导航模式)去用一个更宽的LOGO去代替标准的ICON
③参看setDisplayOptions(int)/setDisplayOptions(int,int)
NAVIGATION_MODE_LIST:
①列表导航模式,这个导航模式在Activity中呈现一个菜单列表供导航代替静态的text标题。如,提供给用户一个下拉列表的导航
NAVIGATION_MODE_STANDER:
①标准导航模式,由一个logo或icon和一个含有可选的子标题的text标题。
②点击这样组成的任何一个都会宿主Activity中调用一个带有ID为android.R.home的MenuItem的函数onOptionSelected
③标准导航模式:点击事件。onOptionsItemSelected中通过switch case选择ID条件为android.R.id.home下处理相关内容
NAVIGATION_MODE_TABS:
①选项卡导航模式,这个导航模式在Activity中呈现一些列的用于导航的选项卡代替静态文字模式


9.构造函数:

public ActionBar()


10.公共方法:

public abstract void removeOnmenuVisibleListener(ActionBar.OnMenuVisibilityListener listener)
①移除一个menu visibility监听器。这个监听器将不会接收menu visibility 变化事件
②参数:
listener - 先前已经添加被移除的监听器
public abstract void addOnMenuVisbilityListener(ActionBar.OnMenuVisibiltyListener litener)
①添加一个listener去响应菜单可见性变化事件。
②参数:
listener:将要被添加的新的listener
public abstract void addTab(ActionBar.Tab tab,boolean setSelected)
①在选项卡导航模式添加一个选项卡,
②并且添加到选项卡列表的最后
③参数:
tab - 被添加的ActionBar.Tab
setSelected - true,false:是否被将添加的Tab设置为选中状态
public abstract void addTab(ActionBar.Tab tab, int postion)
①在选项卡导航模式下添加一个选项卡
②并且添加Tab插到postion的位置
③如果这是第一个选项卡,添加后默认为selected
④参数:
tab - 被添加的选项卡
postion - 添加到的位置
public abstract void addTab(ActionBar.Tab tab, int postion, boolean setSelected)
①在选项卡导航模式下添加选项卡
②这个选项卡将会被插入position的位置
③参数:
tab - 同上
position - 同上
setSelected - 同上
public abstract void addTab(ActionBar.Tab tab)
①在选项卡导航模式下添加一个选项卡,
②并且添加到选项卡列表的最后
③如果这是第一个选项卡,添加后默认为selected
④参数:
tab - 被添加的选项卡
public abstract ActionBar.Tab getSelectedTab()
①如果在选项卡导航并且至少有一个选项卡,则返回当前Selected的tab
②返回:
selected选项卡或null
public abstract ActionBar.Tab getTabAt(int index)
①如果在选项卡导航模式下,返回指定index的ActionBar.Tab
②参数:
index - 移除的ActionTab的index
public abstract void removeTab(ActionBar.Tab tab)
①从ActionBar上移除指定的ActionBar.Tab。如果该ActionBar.Tab是selected的,则首先将该ActionBar.Tab置为deselected,然后设置另一个tab为Selected如果有的话
②参数:
tab - 被移除的tab
public abstract void removeTabAt(int postion)
①从ActionBar上移除指定位置的ActionBar.Tab。如果该ActionBar.Tab是selected的,则首先将该ActionBar.Tab置为deselected,然后设置另一个tab为Selected如果有的话
②参数:
position - 指定移除的位置
public abstract void selectTab(ActionBar.Tab tab)
①选择指定的ActionBar.Tab
②如果不是该ActionBar的child,将被添加到该ActionBar中
③参数:
tab - 被选的tab
public abstract int getTabCount()
①返回当前注册到ActionBar中tab数量
②返回:
当前注册到ActionBar中tab数量
public abstract Action.Tab newTab()
①创建返回一个新的ActionBar.Tab对象
②这个对象并不在ActionBar中直到被添加。
③返回:
返回一个新的ActionBar.Tab对象
public abstract void removeAllTabs()
①移除所有的ActionBar.Tab对象
②取消选择当前的ActionBar.Tab
public abstract View getCustomView()
①返回:
当前自定义的视图
public abstract void setCustomView(int resId)
①设置ActionBar为自定义导航模式,为自定义导航模式提供一个视图
②自定义导航视图将会出现在应用程序application和Action Buttons之间,并且尽可能的占用任何空间. 常见自定义导航视图的用例可能包括一个含有自动提示地址栏的浏览器或者其他不能很好转换到已提供导航模式(已经提供的导航模式:LIST、TABS、STANDER)的导航机制
③自定义导航模式必须设置DISPLAY_SHOW_CUSTOM来显示自定义视图
④参数:
resId - 用来填充ActionBar的布局id
⑤参看:setDisplayOptions(int, int)
public abstract void setCustomView(View view)
①同上
②★此处并不需要自定义导航模式必须设置DISPLAY_SHOW_CUSTOM来显示自定义视图
②参数:
view - 用来放置ActionBar的自定义导航视图
public abstract void setCustomView(View view, ActionBar.LayoutParams layoutParams)
①设置ActionBar为自定义导航模式,为自定义导航模式提供一个视图
②自定义导航视图将会出现在应用程序application和Action Buttons之间,并且尽可能的占用任何空间. 常见自定义导航视图的用例可能包括一个含有自动提示地址栏的浏览器或者其他不能很好转换到已提供导航模式(已经提供的导航模式:LIST、TABS、STANDER)的导航机制
③自定义导航模式必须设置DISPLAY_SHOW_CUSTOM来显示自定义视图
④参数:
view - 用来放置ActionBar的自定义导航视图
layoutParams - 用来设置view在ActionBar如何布局
⑤参看:setDisplayOptions(int, int)
public abstract int getDisplayOptions()
public abstract void setDisplayOptions(int options,int mark)
public abstract void setDisplayOptions(int options)
public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp)
①参看:DISPLAY_HOME_AS_UP
public abstract void setDisplayShowCutomEnable(boolean showCutom)
①参看:DISPLAY_SHOW_CUSTOM
public abstract void setDisplayShowHomeEnable(boolean showHome)
①参看:DISPLAY_SHOW_HOME
public abstract void setDisplayShwoTitleEnable(boolean showTitle)
①参看:DISPLAY_SHOW_TITLE
public abstract void setDisPlayUseLogoEnable(boolean useLogo)
①参看:DISPLAY_USE_LOGO
void setHomeButtonEnable(boolean enable)
①启用或禁用home组成按钮在ActionBar的一角上(注意:这里Home/up是在ActionBar上的,并不是手机系统的Home键)
②API<14时默认值为14,当API>=14时,需要调用这个方法去启用home组成按钮。
③参看 DISPLAY_HOME_AS_UP
④参数:
enable - true,启用;false,禁止
public abstract int getNavigationItemCount()
①返回在当前的导航模式有多少导航项
public abstract int getNavigationMode()
①返回当前导航模式,下面3个中的一个:
NAVIGATION_MODE_STANDARD
NAVIGATION_MODE_LIST
NAVIGATION_MODE_TABS
public abstract int getSelectedNavigationIndex()
①获取在list或Tabbed导航模式中selected的导航项index
abstract void setListNavigationCallbacks(SpinnerAdapter adapter, ActionBar.OnNavigationListener callback)
abstract void setNavigationMode(int mode)
abstract void setSelectedNavigationItem(int postion)
public abstract CharSequence getSubtitle()

①返回当前ActionBar子标题,如果使用getNavigationMode()返回的不是NAVIGATION_MODE_STANDARD,则返回null
public abstract CharSequence getTitle()
①返回当前ActionBar标题,如果使用getNavigationMode()返回的不是NAVIGATION_MODE_STANDARD,则返回null
abstract void setSubtitle(int resId)
①Set the action bar's subtitle. This will only be displayed if DISPLAY_SHOW_TITLE is set.
abstract void setSubtitle(CharSequence subtitle)
①Set the action bar's subtitle. This will only be displayed if DISPLAY_SHOW_TITLE is set.
abstract void setTitle(int resId)
①Set the action bar's title. This will only be displayed if DISPLAY_SHOW_TITLE is set.
abstract void setTitle(CharSequence subtitle)
①Set the action bar's title. This will only be displayed if DISPLAY_SHOW_TITLE is set.
public Context getThemedContext()
abstract void show();
public abstract void hide();
public abstract boolean isShowing()
public abstract int getHeight()
void setHomeActionContentDescription(CharSequence description)
void setHomeActionContentDescription(int resId)
void setHomeAsUpIndicator(Drawle indicator)

①Set an alternate drawable to display next to the icon/logo/title when DISPLAY_HOME_AS_UP is enabled. This can be useful if you are using this mode to display an alternate selection for up navigation, such as a sliding drawer.
②If you pass null to this method, the default drawable from the theme will be used.
③If you implement alternate or intermediate behavior around Up, you should also call setHomeActionContentDescription() to provide a correct description of the action for accessibility support.
void setHomeAsUpIndicator(int resId)
①Set an alternate drawable to display next to the icon/logo/title when DISPLAY_HOME_AS_UP is enabled. This can be useful if you are using this mode to display an alternate selection for up navigation, such as a sliding drawer.
②If you pass null to this method, the default drawable from the theme will be used.
③If you implement alternate or intermediate behavior around Up, you should also call setHomeActionContentDescription() to provide a correct description of the action for accessibility support.
abstract void setIcon(Drawable icon)
①Set the icon to display in the 'home' section of the action bar. The action bar will use an icon specified by its style or the activity icon by default. Whether the home section shows an icon or logo is controlled by the display option DISPLAY_USE_LOGO.
abstract void setIcon(int resId)
①Set the icon to display in the 'home' section of the action bar. The action bar will use an icon specified by its style or the activity icon by default. Whether the home section shows an icon or logo is controlled by the display option DISPLAY_USE_LOGO.
abstract void setLogo(int resId)
①Set the logo to display in the 'home' section of the action bar. The action bar will use a logo specified by its style or the activity logo by default. Whether the home section shows an icon or logo is controlled by the display option DISPLAY_USE_LOGO.
abstract void setLogo(Drawable logo)
①Set the logo to display in the 'home' section of the action bar. The action bar will use a logo specified by its style or the activity logo by default. Whether the home section shows an icon or logo is controlled by the display option DISPLAY_USE_LOGO.
public abstract void setBackgroundDrawable(Drawable d)
①Set the ActionBar's background. This will be used for the primary action bar.
void setSplitBackgroundDrawable(Drawable d)
①Set the ActionBar's split background. This will appear in the split action bar containing menu-provided action buttons on some devices and configurations.
②You can enable split action bar with uiOptions
void setStackedBackgroundDrawable(Drawable d)
①Set the ActionBar's stacked background. This will appear in the second row/stacked bar on some devices and configurations.

0 0
原创粉丝点击