• 建立V7包库(Library)项目以供其他项目引用

    就是建项目
    服务器君一共花费 17.623 ms 进行了 4 次数据库查询,努力地为您提供了这个页面。
    广告很萌的

    以前3.0以前的版本要使用ActionBar,必须使用国外大牛写的ActionBarSherlock这个开源项目。2013年的Google I/O大会之后,Google官方在android-support-v7包中添加了ActionBar,开始让2.1以后的版本支持ActionBar,从此以后曾经最火的Android开源项目ActionBarSherlock可以退出历史舞台了。

    要是用v7包中ActionBar也很简单,但有一个需要注意的地方。有些人可能刚开始仅仅是把android-support-v7-appcompat.jar导入项目中,但是在设置Activity的theme时会报错,提示找不到"@style/Theme.AppCompat"。这是由于我们要把v7和资源文件一起导入才行,仅仅导入V7包是不够的。

    Eclipse下具体使用步骤为(摘自Android官网):

    Create a library project based on the support library code:

    1. Make sure you have downloaded the Android Support Library using the SDK Manager.
    2. Create a library project and ensure the required JAR files are included in the project's build path:
      1. Select File > Import.
      2. Select Existing Android Code Into Workspace and click Next.
      3. Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding theappcompat project, browse to /extras/android/support/v7/appcompat/.
      4. Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
      5. In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar andandroid-support-v7-appcompat.jar files to the build path.
      6. Right-click the project and select Build Path > Configure Build Path.
      7. In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
      8. Uncheck Android Dependencies.
      9. Click OK to complete the changes.

    You now have a library project for your selected Support Library that you can use with one or more application projects.

    Add the library to your application project:

    1. In the Project Explorer, right-click your project and select Properties.
    2. In the Library pane, click Add.
    3. Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.
    4. In the properties window, click OK.

    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:

    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.

    简单地说,就是:

    1. 先升级SDK的Support Library;
    2. 以SDK目录下/extras/android/support/v7/appcompat/为基础新建一个项目;
    3. 将这个项目libs下的v4、v7包Build Path;
    4. Configure Build Path。
    基于5.0的V7包库项目

    然后这个项目就可以被其它项目引用了。

更多 推荐条目

Welcome to NowaMagic Academy!

现代魔法 推荐于 2013-02-27 10:23   

本章最新发布
随机专题
  1. [软件工程与项目管理] 浏览器的CSS解析 7 个条目
  2. [PHP程序设计] PHP中的Hash算法 3 个条目
  3. [JavaScript程序设计] 关于HTTP Keep-Alive 6 个条目
  4. [移动开发] Layout_weight属性解析 5 个条目
  5. [运维管理] 路由器与交换机 4 个条目
  6. [Python程序设计] Django数据库模型 6 个条目
  7. [Python程序设计] Django 入门知识浅介 10 个条目
  8. [移动开发] 刷机与root相关 2 个条目
  9. [智力开发与知识管理] 整体性学习策略 9 个条目
  10. [JavaScript程序设计] jQuery与表单操作 2 个条目
  11. [移动开发] Android抽屉导航NavigationDrawer 5 个条目
  12. [Python程序设计] Python语言概述 6 个条目
窗口 -- [博客]