Adding the Action Bar


  As mentioned above, this guide focuses on how to use the ActionBar APIs in the support library. So before you can add the action bar, you must set up your project with the appcompat v7 support library by following the instructions in the Support Library Setup.

Once your project is set up with the support library, here's how to add the action bar:

  1. Create your activity by extending ActionBarActivity.
  2. Use (or extend) one of the Theme.AppCompat themes for your activity. For example:
    <activity android:theme="@style/Theme.AppCompat.Light" ... >

  Now your activity includes the action bar when running on Android 2.1 (API level 7) or higher.

On API level 11 or higher

  The action bar is included in all activities that use the Theme.Holo theme (or one of its descendants), which is the default theme when either the targetSdkVersion or minSdkVersion attribute is set to "11" or higher. If you don't want the action bar for an activity, set the activity theme to Theme.Holo.NoActionBar.

  主题Theme.Holo.NoActionBar不支持ActionBar,Theme.Holo 支持ActionBar

Removing the action bar

You can hide the action bar at runtime by calling hide(). For example:

 ActionBar actionBar = getSupportActionBar();
 actionBar.hide();

On API level 11 or higher

  Get the ActionBar with the getActionBar() method.

When the action bar hides, the system adjusts your layout to fill the screen space now available. You can bring the action bar back by calling show().

隐藏:ActionBar.hidden(),显示:ActionBar.show()

  Beware that hiding and removing the action bar causes your activity to re-layout in order to account for the space consumed by the action bar. If your activity often hides and shows the action bar, you might want to enable overlay mode. Overlay mode draws the action bar in front of your activity layout, obscuring the top portion. This way, your layout remains fixed when the action bar hides and re-appears. To enable overlay mode, create a custom theme for your activity and set windowActionBarOverlay to true. For more information, see the section below about Styling the Action Bar.

注意: 如果经常隐藏,显示,那么要用overlay mode

ActionBar官方教程(2)选主题让应用支或不支持ActionBar及支持ActionBar的应用如何隐藏和显示的更多相关文章

  1. ActionBar官方教程(11)自定义ActionBar的样式(含重要的样式属性表及练习示例)

    Styling the Action Bar If you want to implement a visual design that represents your app's brand, th ...

  2. ActionBar官方教程(10)ActionBar的下拉列表模式

    Adding Drop-down Navigation As another mode of navigation (or filtering) for your activity, the acti ...

  3. ActionBar官方教程(9)ActionBar的顶部tab模式(注意,已经被弃用)

    This interface is deprecated.Action bar navigation modes are deprecated and not supported by inline ...

  4. ActionBar官方教程(6)把图标变成一个返回到上级的按钮,同一个app间,不同app间,不同fragment间

    Navigating Up with the App Icon Enabling the app icon as an Up button allows the user to navigate yo ...

  5. ActionBar官方教程(5)ActionBar的分裂模式(底部tab样式),隐藏标题,隐藏图标

    Using split action bar Split action bar provides a separate bar at the bottom of the screen to displ ...

  6. ActionBar官方教程(3)更改标题处的图片

    Using a logo instead of an icon By default, the system uses your application icon in the action bar, ...

  7. ActionBar官方教程(1)简介及各区域介绍

    Action Bar The action bar is a window feature that identifies the user location, and provides user a ...

  8. ActionBar官方教程(8)ShareActionProvider与自定义操作项提供器

    Adding an Action Provider Similar to an action view, an action provider replaces an action button wi ...

  9. ActionBar官方教程(7)自定义操作项的view,如何得到它及处理它的事件

    Adding an Action View An action view is a widget that appears in the action bar as a substitute for ...

随机推荐

  1. UICollectionView的简单使用

    ChildModel.h #import <Foundation/Foundation.h> @interface ChildModel : NSObject @property (non ...

  2. 用分治法实现大数乘法,加法,减法(java实现)

    大数乘法即多项式乘法问题,求A(x)与B(x)的乘积C(x),朴素解法的复杂度O(n^2),基本思想是把多项式A(x)与B(x)写成 A(x)=a*x^m+b B(x)=c*x^m+d 其中a,b,c ...

  3. windows phone 操作 http异步返回结果

    wp中为了提升用户体验,砍掉了http的同步操作,仅支持http异步请求,那么该如何及时处理异步操作返回的结果.纠结了很久,终于在技术群中好友的帮助下解决了问题,借助事件,将异步编程模型模式简单的处理 ...

  4. [C#]获取一年中是第几个星期

    关键代码: /// <summary> /// 获取日期是一年中第几个星期 /// </summary> /// <param name="date" ...

  5. 转 修改oracle用户密码永不过期

      1.查看用户的proifle是哪个,一般是default: sql>SELECT username,PROFILE FROM dba_users; 2.查看指定概要文件(如default)的 ...

  6. Linux学习笔记2

    1.系统引导配置文件  # vi /boot/grub/grub.conf   default=0   timeout=5   splashimage=(hd0,0)/grub/splash.xpm. ...

  7. Python 出现需要使用fPIC重新编译的问题

    在已经存在python安装环境的情况下,当安装第三方的包的时候出现报错提示 /usr/bin/ld: .../lib/libpython2.7.a(abstract.o): relocation R_ ...

  8. shell中的重定向(2>&1)

    shell的输出可以分为标准输出和错误输出,2>&1中,2代表错误输出,1代表标准输出,&符号代表后面跟的是代号而不是文件. test.sh echo '我是标准输出' ls / ...

  9. Socket和SignalR

    写到一半停电了,这心情真是哔了狗了,草稿箱竟然也没有!!! 好吧,这篇文档是之前写的记录,现在来完善(还是要完善的). 导读: 附件代码实现: Socket: 定义,同步实现,异步实现,还包括了TCP ...

  10. linux exec函数家族

    1.exec家族一共有六个函数,分别是: (1)int execl(const char *path, const char *arg, ......); (2)int execle(const ch ...