首先介绍下Support Library,为了让在老的sdk版本支持新的功能,而添加的功能库。
分为不同的版本:
v4 Support Library, 为Android 1.6版本设计的
v7 Support Library, 为android 2.1版本设计的
v8 Support Library, 为API level 8版本设计的
v13 Support Library, 为Android 3.2 (API level 13)版本设计的
具体每个版本支持的功能,参考http://developer.android.com/tools/support-library/features.html
我们需要在sdk manager里面下载Support Library。
下面简单说下如何在eclipse添加Support Library,分为两种情况:
一、Library without resources
--->将要添加的.jar复制到你的project的libs目录下
--->右击.jar文件,Build Path->Add to Build Path
二、Library with resources
--->基于Support Library 创建library project:
1, 选择File->Import
2,选择Existing Android Code into Workspace
3,选择jar库文件,比如要添加的是appcompat,就可以<sdk>/extras/android/support/v7/appcompat/目录
4,在这个新的project里,在libs目录下的每个.jar文件都右击Build Path->Add to Build Path
5,右击project,选择Build Path->Configure Build Path
6,在Order and Export选项卡,将刚才添加到Build Path的.jar文件勾选上。例如appcompat就需要勾选android-support-v4.jar和android-support-v7-appcompat.jar文件。
7,不勾选(Uncheck)Android Dependencies
8,点击确定。
--->将创建的Support library project添加到我们当前的project中。
1,右击project,选择Properties。
2,在左边的选项卡中,选择Android。
3,点击Add,将刚才创建的library project添加到进来,比如android-support-v7-compat
4,点击OK。
至此使用support library完成。
有一个注意事项:使用到support library的项目发布的时候最好用ProGuard,这样不仅可以保护源代码,还可以删去support library中没有使用到的内容,可以使打包文件更小。