如何使用android-support-V7包中ActionBar(Eclipse版)
$*********************************************************************************************$
博主推荐:
风萧兮兮易水寒,“天真”一去兮不复还。如何找到天真的那份快乐。小编倾力推荐app: 天真无谐
下载方式:豌豆荚,应用宝,360手机助手,百度手机助手,安卓,91市场搜索:天真无谐
关注我们:查看详情
$*********************************************************************************************$
以前3.0以前的版本要使用ActionBar,必须使用国外大牛写的ActionBarSherlock这个开源项目。今年的Google/IO大会之后,Google官方在android-support-v7包中添加了ActionBar,开始让2.1以后的版本支持ActionBar,从此以后曾经最火的Android开源项目ActionBarSherlock可以退出历史舞台了。
要是用V7包中ActionBar也很简单,但有一个需要注意的地方。有些人可能刚开始仅仅是把android-support-v7-appcompat.jar导入项目中,但是在设置Activity的theme时会报错,提示找不到"@style/Theme.AppCompat"。这是由于我们要把v7和资源文件一起导入才行。
具体使用步骤(针对于Eclipse):
Create a library project based on the support library code:
- Make sure you have downloaded the Android Support Library using the SDK Manager.
- Create a library project and ensure the required JAR files are included in the project's build path:
- Select File > Import.
- Select Existing Android Code Into Workspace and click Next.
- Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the
appcompatproject, browse to<sdk>/extras/android/support/v7/appcompat/. - Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
- In the new library project, expand the
libs/folder, right-click each.jarfile and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both theandroid-support-v4.jarandandroid-support-v7-appcompat.jarfiles to the build path. - Right-click the project and select Build Path > Configure Build Path.
- In the Order and Export tab, check the
.jarfiles you just added to the build path, so they are available to projects that depend on this library project. For example, theappcompatproject requires you to export both theandroid-support-v4.jarandandroid-support-v7-appcompat.jarfiles. - Uncheck Android Dependencies.
- 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:
- In the Project Explorer, right-click your project and select Properties.
- In the Library pane, click Add.
- Select the library project and click OK. For example, the
appcompatproject should be listed as android-support-v7-appcompat. - In the properties window, click OK.
Once your project is set up with the support library, here's how to add the action bar:
- Create your activity by extending
ActionBarActivity. - Use (or extend) one of the
Theme.AppCompatthemes 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.
以上摘自Android官网。
示例代码:
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.folyd.actionbartest"
- android:versionCode="1"
- android:versionName="1.0" >
- <uses-sdk
- android:minSdkVersion="8"
- android:targetSdkVersion="17" />
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:theme="@style/Theme.Base.AppCompat.Light"
- android:name="com.folyd.actionbartest.MainActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
- package com.folyd.actionbartest;
- import android.os.Bundle;
- import android.support.v7.app.ActionBar;
- import android.support.v7.app.ActionBarActivity;
- public class MainActivity extends ActionBarActivity {
- private ActionBar actionBar;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- actionBar = getSupportActionBar();
- actionBar.setDisplayShowHomeEnabled(true);
- }
- }
效果截图:
如何使用android-support-V7包中ActionBar(Eclipse版)的更多相关文章
- Android Support V7 包中 ActionBar的使用
以下示例为API<11,因为API>=11时本来就有ActionBar可以使用,所以不猜讨论范围之内 今天Google发布了最新的API 18,包括众多新的性能,正好最近在研究Action ...
- 转 如何使用V7包中ActionBar(Eclipse版)
http://blog.csdn.net/appte/article/details/11712591 以前3.0以前的版本要使用ActionBar,必须使用国外大牛写的ActionBarSherlo ...
- 如何使用V7包中ActionBar(Eclipse版)
转自:http://blog.csdn.net/appte/article/details/11712591 以前3.0以前的版本要使用ActionBar,必须使用国外大牛写的ActionBarShe ...
- android.support.v4包中的LruCache源码简读
package android.util; import java.util.LinkedHashMap; import java.util.Map; /** * A cache that holds ...
- android 使用android.support.v7 添加ActionBar
当需要在 android 7或更高的版本使用 ActionBar,则可以通过继承ActionBarActivity来实现, 网上有一个开源项目来兼容老版本显示ActionBar的效果:ActionBa ...
- [转]Android 导入v7包常见错误,以及项目引用v7包错误解决
android下v4 v7 v21等包是android系统的扩展支持包,就想windows的系统补丁一个道理. android的扩展包主要是用来兼容低版本的,比如android3.0以后出现 ...
- Android 导入v7包常见错误,以及项目引用v7包错误解决
android下v4 v7 v21等包是android系统的扩展支持包,就想windows的系统补丁一个道理. android的扩展包主要是用来兼容低版本的,比如android3.0以后出现 ...
- android.support.v7.app.AppCompatActivity
1.Android Studio (api 23) 新建项目的时候 Activity public class MainActivity extends AppCompatActivity 2.系统默 ...
- 在项目中引用android.support.v7
在Android开发中,新建的项目可能因为缺少对sopport工程的引用而报错,可以这样解决. 1.项目右键 --> import --> Android --> Existing ...
随机推荐
- boost库:函数对象
函数对象是指那些可以被传入到其它函数或是从其它函数返回的一类函数. 1. boost::bind bind提供了一个机制,是函数与几乎不限数量的参数一起使用,就可以得到指定签名的函数.bind会复制传 ...
- 威胁快报|Bulehero挖矿蠕虫升级,PhpStudy后门漏洞加入武器库
概述 近日,阿里云安全团队监控到Bulehero挖矿蠕虫进行了版本升级,蠕虫升级后开始利用最新出现的PHPStudy后门漏洞作为新的攻击方式对Windows主机进行攻击,攻击成功后会下载门罗币挖矿程序 ...
- bzoj 3011
传送门: http://www.lydsy.com/JudgeOnline/problem.php?id=3011 一想到这个第一反应是树形dp,然后10^18 (' ' ) 所以我直接搞了一个 ...
- UNP学习 广播
一.概述 虽然UDP支持各种形式的地址,但TCP只支持单播地址. 上图要点是: IPv4对多播的支持是可选的,而IPv6则时必须的. IPv6没有提供对广播的支持:当使用广播的IPv4应用程序一直到I ...
- 容器————priority_queue
#include <queue> 与queue不同的是可以自定义其中数据的优先级,让优先级高的先出队列. 优先队列具有队列的所有特性,包括基本操作,只是在这基础上添加了内部的一个排序,它本 ...
- JMeter 阶梯式加压测试插件 Stepping Thread Group
在日常性能测试过程中,有时需要对被测对象不断的增加压力,直至达到某个值后,并持续运行一段时间.这里将借助jmeter插件模拟这种情况. 本文介绍在jmeter中,使用插件Stepping Thread ...
- Sqli labs系列-less-5&6 报错注入法(上)
在我一系列常规的测试后发现,第五关和第六关,是属于报错注入的关卡,两关的区别是一个是单引号一个是双引号...当然我是看了源码的.... 基于报错注入的方法,我早就忘的差不多了,,,我记的我最后一次基于 ...
- Spring核心——Bean的依赖注入
依赖注入在设计模式与IoC这篇文章中,介绍了Spring基础的三大支柱的两项内容——IoC.Bean.本篇将继续围绕着Bean的创建时的注入方式来介绍Spring的核心思想与设计模式. 天底下所有面向 ...
- Elasticsearch搜索查询语法
- sql审核工具调研安装-sqlAdvisor和soar
sql审核工具调研 基于soar的sql审核查询平台: https://github.com/beiketianzhuang/data-platform-soar 1.美团工具sqlAdvisor工 ...