`

Develop_Tools:Support Library

 
阅读更多

 

         Support Library

 

         Features

 

        Support Library Features

        android support library包包含了一系列可以include进你的应用的库。这些库中每一个都有其支持的版本范围和特性。

        本文将讲述每个库对应的新特性和支持版本,以帮助你决定include进哪一个到你的应用。一般地,我们推荐使用V4 support 和v7 appcompat库。因为它们支持广泛范围的android版本,提供推荐用户使用的界面模式API。

        为了使用这些库,你必须下载库文件到你的Android SDK安装目录。如何下载遵循Support Library Setup的指导。下载完后,你还必须加你需要的库到你的application。下面有如何加相应的库到你的应用你需要的注意点。

 

        v4 Support Library

        该库适用于android 1.6(API 4)或者更高的版本。相比于其他Support库,v4库包含了绝大部分的API。包括:对应用组件的支持、用户界面特性、数据访问处理、网络连接和通用工具类。下面是几个v4包里的关键类:

        1.App Component

         *Fragment - 支持Fragment界面和功能的封装类。提供布局在大屏幕和小屏幕设备之前的切换和调整。

         *NotificationCompat - 添加对富信息通知特性的支持

         *LocalBroadcastManager - 允许应用能容易的注册只接受自己application的intent的广播

        2.用户界面

         *ViewPager - 一个管理一组views的ViewGroup。用户能在一组Views之间切换。

         *PagerTitleStrip - add 一个非交互的title条,该title条能加入ViewPager里作为ViewPager的子视图。

         *PagerTabStrip - 添加用于Pager里各个页面之间切换的导航控件。其也能用于ViewPager里。

         *DrawerLayout - 用于对Navigation Drawer的支持---能从一个window的边缘pull in.

         *SlidingPaneLayout - Adds widget for creating linked summary and detail views that appropriately adapt to various screen sizes.

        3.Accessibility

         *ExploreByTouchHelper - 实现定制view访问支持的帮助类

         *AccessibilityEventCompat - 对AccessbilityEvent的支持。更多的关于访问实现的信息,see Accessibility。

         *AccessibilityNodeInfoCompat - 添加AccessibilityNodeInfo的支持

         *AccessibilityNodeProviderCompat - 用于支持AccessibilityNodeProvider

         *AccessibilityDelegateCompat - 用于支持View.AccessibilityDelegate

        4.Content

         *Loader - 用于数据异步加载。该库也提供了该类特定的实现,例如CursorLoader 和AsyncTaskLoader

         *FileProvider - 用于在不同应用之间的私有文件共享。

 

        该库也有一些其他的API,关于V4库更多更全更详细的信息请参考API reference里android.support.v4包。

        你下载了Android Support 库后,该库位于<sdk>/extras/android/support/v4/目录下。该库并不包含用户界面资源。为了将该库导入你的app工程,遵循 adding libraries without resources 的指导。

 

         The Gradle build script dependency identifier for this library is as follows:

         

com.android.support:support-v4:18.0.+
This dependency notation specifies the release version 18.0.0 or higher.
 

 

 

        v7 Libraries

        该库被用于Android2.1(API 7)或更高的版本。这些库提供专门的特性集,能彼此独立地include进你的应用。

 

        v7 appcompat library

        该库增加对Action Bar用户界面设计模式的支持。

        注:该库依赖V4库。如果你正用Ant,确保v4库加入了你的库classpath。

 

        下面是v7 appcompat library里的几个关键类:

        *ActionBar - 提供Action Bar用户界面模式实现。更多使用Action Bar的信息,see Action Bar 开发者向导。

        *ActionBarActivity - 实现了Action Bar的Activity。如果使用Action Bar ,Activity应该继承该类。

        *ShareActionProvider - 用于标准的分享action的支持(例如email或者分享到其他的application),其能include到action bar里。

 

        该库位于<sdk>/extras/android/support/v7/appcompat/目录下,该库包含用户界面资源。为了include该库进入你的android app,遵循adding libraries with resources的说明

 

        The Gradle build script dependency identifier for this library is as follows:

         

com.android.support:appcompat-v7:18.0.+
This dependency notation specifies the release version 18.0.0 or higher.
 

 

        v7 gridlayout library

        该库增加对GridLayout类的支持,该类允许你像矩形单元格网格的形式排列元素。更多信息,参见API reference里的android.support.v7.widget包

        该库位于<sdk>/extras/android/support/v7/gridlayout/下,该库包括了用户界面resources。为了在你的工程里使用该库,参见adding libraries with resources的指导。

 

         The Gradle build script dependency identifier for this library is as follows:

        

com.android.support:gridlayout-v7:18.0.+
This dependency notation specifies the release version 18.0.0 or higher.
 

 

        v7 mediarouter library

        该库提供了MediaRouter、MediaRouteProvider和相关的媒体类,用于支持Google Cast developer preview.

        一般地,the APIs in the v7 mediarouter library provide a means of controlling the routing of media channels and streams from the current device to external screens, speakers, and other destination devices。

        该库提供了发布专门app媒体路由的provider,用于发现和选择目的设备,检查媒体专题或者更多。更多该库的详细信息,参见 android.support.v7.media 包.

         v7 mediarouter library位于<sdk>/extras/android/support/v7/mediarouter/。其作为库工程提供,依赖于v7 appcompat 库。因此,当建立你的工程时,在你的 build path里这两个包都需要导入。如果你正使用ADT工具(如eclipse)开发,确保 android-support-v7-mediarouter.jar 和 android-support-v7-appcompat.jar文件都引入。

         如果你正使用android Studio,你仅仅需要做的就是指定Gradle build script dependency identifier:com.android.support:support-v7-mediarouter:<revision>,"18.0.0"是库有效的最小版本,例如:

com.android.support:mediarouter-v7:18.0.+

        The v7 mediarouter library APIs introduced in Support Library r18 are subject to change in later revisions of the Support Library. At this time, we recommend using the library only in connection with the Google Cast developer preview.

 

        v8 Support Library

        该库被用于API 8或者更高的版本。它加入对RenderScript计算框架的支持。这些APIs包含在android.support.v8.renderscript包里。你应该意识到include这些APIs的步骤是非常不同于其他支持库的APIs。

        更多的信息,参见RenderScript开发者向导。

        注:Android Eclipse plugin 和Ant构建工具能支持和方便你使用RenderScript。但当前Android Studio或者基于Gradle的build并不支持。

 

        v13 Support Library

        该库适用于android3.2(API 13)及以上的版本。该库增加了对Fragment用户界面模式的支持(用FragmentCompat类),也提供了其他的Fragment支持类。关于fragment的更多信息,参见Fragment开发向导。更多关于V13库的信息,参见android.support.v13包

        该库位于<sdk>/extras/android/support/v13/目录下。该库并不包含用户界面资源。为了include该库进入工程,遵循adding libraries without resources的向导。

 

         Gradle构建脚本依赖标识如下:

         com.android.support:support-v13:18.0.+

         如上依赖描述指定release版本为18.0.0.0或者更高。

 

 

 

         Support Library Setup

 

        怎么样在你的开发功能里使用支持库取决于:你想要使用那些新特性;以及你的app支持的android平台版本范围。

        本文指导你如何下载支持库包,以及如何添加相应的库到你的开发环境。

 

        Downloading the Support Libraries

        下载支持库,通过SDK Manager。

 

        Choosing Support Libraries

        添加支持库到你的app之前,决定你想要使用什么新特性,以及你的app支持的SDK版本范围。

 

        Adding Support Libraries

        为了使用支持库,你必须修改你的开发环境里的app工程的classpath依赖。对每一个你想要使用的支持库,你都必须这样做。

 

        一些库在编译的代码类之外还有资源文件,例如像图片或者XML文件。例如,v7 appcompat 和v7 gridlayout库

        如果你不确定哪些库含有资源。check Support Library Features。下面部分描述了如何添加支持库到你的app工程。

 

        Adding libraries without resources

        为了加不含资源的库到你的app工程:

        Using Eclipse

        1.确保你已下载了Android Support 库

        2.在你的工程的更目录下产生libs/文件夹

        3.复制JAR文件从Android SDK安装目录(例如:<SDK>/extras/android/support/v4/android-support-v4.jar)到应用工程的libs/下.

        4.右键点击JAR文件,选择 “Build Path -> Add to Build Path

 

        Using Android Studio

        1.确保你已下载了Android Support Repository

        2.打开你的app里的build.gradle文件。

        3.添加支持库到你的依赖部分。例如,如果想键入v4库,添加如下语句:

        

dependencies {
...
compile "com.android.support:support-v4:18.0.+"
}

 

        Adding libraries with resources

        为了添加包含资源的库(例如支持action bar的v7 appcompat):

        Using Eclipse

        产生一个基于支持库代码的库工程:

         1.确保你已下载了Android Support Library.

         2.产生库工程,确保需要的JAR文件include在你的功能build路径里。

                1。选择“File -> Import"

                2. 选择”Existing Android Code Into Workspace",然后点击“Next”。

                3. Browse 到SDK安装目录 然后定位到Support库文件夹。例如,如果你要加appcompat工程,browse到<sdk>/extras/android/support/v7/appcompat/

                4. 点击“Finish”导入该工程。对应于v7 appcompat工程,你应该看到一个标题为 android-support-v7-appcompat的新工程。

                5. 在该新工程里,展开libs/文件夹,右键点击每一个.jar文件,选择“Build Path -> Add to Build Path",例如,当产生v7 appcompat工程时,android-support-v4.jar和 android-support-v7.jar都加到build路径。

                6.右键点击库工程文件夹,选择”Build Path -> Configure Build Path".

                7. 在"Order and Export"Tab页,勾选你刚才添加到build路径的.jar文件,这样这些依赖库对与主工程就可用了。例如:appcompat工程要求既导入android-support-v4.jar也要导入android-support-v7-appcompat.jar包

                8.取消勾选“Android Dependencies”

                9. 点击“OK"完成

 

            现在你有了一个你选择的支持库的库工程,该库工程能给多个app使用。

 

            添加该库到应用工程:

                 1. 在Project Explorer视图里,右键点击你的工程,然后选择”Properties“

                 2. 在对话框左边的目录面板里,选择”Android“

                 3. 在Library面板,点击”Add“按钮

                 4. 选择库工程,然后点击”OK“,例如,appcompat工程被列出为 android-support-v7-appcompat

                 5. 在这属性窗口,点击"OK"

            注:如果你正使用android-support-v7-mediarouter库,你应该注意该库依赖android-support-v7appcompat库。为了v7 mediarouter库能编译通过,你必须导入相应的库工程。

 

            Using Android Studio

             1.确保你已下载了android Support Repository

             2.打开你的应用里的build.gradle文件

             3.添加支持库特性工程标识符到dependencies部分。例如,为了include appcompat工程,添加”comile ”com.android.support:appcompat-v7:18.0.+"“到依赖部分。像如下显示的:

dependencies {
...
compile "com.android.support:appcompat-v7:18.0.+"
}

 

 

         Using Support Library APIs

         Support库类对已存在的框架API提供支持。特别地,支持库可能和已有框架类有相同的名字。但是它们位于android.support类包里,或者由*Compat后缀。

        注意:当使用支持库里的类时,确保你导入了正确的包。例如,当使用ActionBar类时:

               * 导入android.support.v7.app.ActionBar(当使用支持库时)

               * android.app.ActionBar(当开发仅仅API11或更高版本时)

        提示:在你的app工程里导入支持库后,我们强烈地推荐在发布你的app之前使用ProGuard工具处理你的代码。另外,为了保护你的源代码,ProGuard工具也移除了导入在你的app里的第三方库里的没有用到的类.这确保了你的应用包大小尽可能的小。更多的信息,参见ProGuard。

 

        更多使用支持库新特性的参考请参阅training classes,guides和samples。更多支持库的类和方法API,参见android.support包。

 

        Manifest Declaration Changes

        如果使用支持库为了实现你的app向后兼容,必须更新你的app的Manifest文件。特别地,你应该更新<uses-sdk>标签的android:minSdkVersion元素到更低的版本数。如下所示:

<uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17" />

 

 

        如上告诉google play你的app能安装在android2.1(API 7)或者更高版本的设备上。

 

        提示:如果你同时导入v4和v7 appcompat包,你应该指定最小的SDK版本为“7”(而不是“4”。),你导入的多个库支持的最低版本中的最高版本确定了你的app能安装上的最低版本。

 

        Code Samples

         Each Support Library includes code samples to help you get started using the support APIs. The code is included in the download from the SDK Manager and is placed inside the Android SDK installation directory, as listed below:

 

        4v Samples: <sdk>/extras/android/support/samples/Support4Demos/

        7v Samples: <sdk>/extras/android/support/samples/Support7Demos/

        13v Samples: <sdk>/extras/android/support/samples/Support13Demos/

        App Navigation: <sdk>/extras/android/support/samples/SupportAppNavigation/

分享到:
评论

相关推荐

    ObjC.pdf 英文

    ■ An object-oriented programming language and support library ■ A library of objects ■ A set of development tools This document is about the first component of the development environment—the ...

    sas web develop guid book

    This is a library of Ant tasks that help ... It includes the "old" .NET tasks like a C# compiler task but also comes with support for NUnit testing or running the popular NAnt or MSBuild build tools.

    The Objective-C Programming Language-2006.pdf

    ■ An object-oriented programming language and support library This document is about the third component of the development environment—the programming language and its runtime environment....

    8-07-14_MegaCLI for linux_windows

    LSIP200232954 (DFCT) Need to Support all the MFC default values in the command AdpSettings. LSIP200245968 (DFCT) In EFICLI not able to flash latest firmware to controller without using -nosigchk -...

    python3.6.5参考手册 chm

    DTrace and SystemTap probing support Other Language Changes New Modules secrets Improved Modules array ast asyncio binascii cmath collections concurrent.futures contextlib datetime decimal...

    Professional MFC with VC6

    This book will give a detailed discussion of the majority of classes present in Microsoft's application framework library, and the tools provided by Visual C++ 6. Throughout the book, you will learn ...

    Enterprise Development with Flex

    develop a sample AIR application that automatically synchronizes local and remote databases to support your sales force; get solutions for leveraging AMF protocol and synchronizing Flex client data ...

    Professional Android 4 Application Development 源代码

    Android Development Tools Chapter 3: Creating Applications and Activities What Makes an Android Application? Introducing the Application Manifest File Using the Manifest Editor Externalizing Resources...

    SQL Server 2008 R2详解手册.pdf

    The accompanying CD-ROM contains an extraordinary library of practical tools and information including sample databases and all code examples. Whether you’re responsible for SQL Server 2008 analysis,...

    ComponentOne 2012 V2 Studio for Silverlight 2/3

    ComponentOne has partnered with Esri, the leading online map and GIS provider, to bring you the best mapping tools and UI controls together in one package. Easily transform GIS data into business ...

    ComponentOne Studio for Silverlight 2013 v1 2/3

    ComponentOne has partnered with Esri, the leading online map and GIS provider, to bring you the best mapping tools and UI controls together in one package. Easily transform GIS data into business ...

    Sending Email using MAPI - A COM DLL(sending email demo and soucecode)

    During the software development, I have seen many applications that requires incorporating email support. I remember, once I was to develop an application, which sends emails at the specific time to ...

    ComponentOne 2012 V2 Studio for Silverlight(完整安装)

    ComponentOne has partnered with Esri, the leading online map and GIS provider, to bring you the best mapping tools and UI controls together in one package. Easily transform GIS data into business ...

    FastReport.v4.9.81 for.Delphi.BCB.Full.Source企业版含ClientServer中文修正版

    FastReport® provides all the necessary tools to develop reports, including a visual report designer, a reporting core, and a preview window. It can be used in the CodeGear (exBorland) Delphi 4-2010,...

    ComponentOne 2012 V2 Studio for Silverlight 3/3

    ComponentOne has partnered with Esri, the leading online map and GIS provider, to bring you the best mapping tools and UI controls together in one package. Easily transform GIS data into business ...

    ComponentOne Studio for Silverlight 2013 v1

    ComponentOne has partnered with Esri, the leading online map and GIS provider, to bring you the best mapping tools and UI controls together in one package. Easily transform GIS data into business ...

    Mastering.Android.Game.Development.1783551771

    Gaming has historically been a strong driver of technology, whether we're talking about hardware or software performance, the variety of input methods, or graphics support, and the Android game ...

    ComponentOne Studio for Silverlight 2013 v1 3/3

    ComponentOne has partnered with Esri, the leading online map and GIS provider, to bring you the best mapping tools and UI controls together in one package. Easily transform GIS data into business ...

    ComponentOne Studio for Silverlight 2012 v3 1/3

    ComponentOne has partnered with Esri, the leading online map and GIS provider, to bring you the best mapping tools and UI controls together in one package. Easily transform GIS data into business ...

Global site tag (gtag.js) - Google Analytics