Android培训翻译_使用Android支持库

本文是Android开发官网 Android培训的中文翻译,限于译者水平有限,便于大家指正,采用中英文对照风格

更多已翻译内容请见 Android培训翻译_目录


 

This lesson teaches you to
这节课教你:

  1. Set Up Your Project With the Support Library
    在你的项目中安装支持库
  2. Import the Support Library APIs
    导入支持库API

You should also read
你该看看

The Android Support Library provides a JAR file with an API library that allow you to use some of the more recent Android APIs in your app while running on earlier versions of Android. For instance, the Support Library provides a version of the Fragment APIs that you can use on Android 1.6 (API level 4) and higher.
Android支持库提供了一个JAR文件的API库,使你用最新的API开发的应用程序能在早期版本的Android上运行。例如,支持库提供了Fragment API的一个版本,你可以使用在早期的Android1.6 ( API 4级)或更高版本上。

 

This lesson shows how to set up your app to use the Support Library in order to use fragments to build a dynamic app UI.
这节课说明如何配置你的应用程序使用的支持库,以便用fragment构建一个动态的应用程序UI。

 

Set Up Your Project With the Support Library
在你的项目中设置支持库


Figure 1. The Android SDK Manager with the Android Support package selected.
图1. 在Android SDK管理器中选择 Android支持库

 

To set up your project: 设置你的项目

  1. Downlad the Android Support package using the SDK Manager
    使用SDK管理器下载Android支持包
  2. Create a libs directory at the top level of your Android project.
    在你的Android项目根文件下创建libs文件夹
  3. Locate the JAR file for the library you want to use and copy it into the libs/directory.
    找到你要使用的Jar库文件,复制到 libs/ 文件夹下。

    For example, the library that supports API level 4 and up is located at<sdk>/extras/android/support/v4/android-support-v4.jar.
    例如,支持API 4级的库的位置为: <sdk>/extras/android/support/v4/android-support-v4.jar。

  4. Update your manifest file to set the minimum API level to 4and the target API level to the latest release:
    更新你的manifest文件设置最小API 级别为4,并且将目标API 级别设置为最新发布版
    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="16" />

 

Import the Support Library APIs
导入支持库API


 

The Support Library includes a variety of APIs that were either added in recent versions of Android or don't exist in the platform at all and merely provide additional support to you when developing specific application features.
支持库包含各种API,包括最新版本Android中添加API的或是平台上根本不存在而只是开发特别功能才提供的额外API。

 

You can find all the API reference documentation for the Support Library in the platform docs at android.support.v4.*.
这里你可以找到所有的支持库API参考文档:android.support.v4.*

 

Warning: To be sure that you don't accidentally use new APIs on an older system version, be certain that you import the Fragment class and related APIs from the android.support.v4.apppackage:
警告:请确认,别不小心在一个旧的系统版本上使用新的API,确认你导入的fragment类和相关API来自 android.support.v4.app 包。

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
...

 

When creating an activity that hosts fragments while using the Support Library, you must also extend the FragmentActivity class instead of the traditional Activity class. You'll see sample code for the fragment and activity in the next lesson.
当你使用支持库的创建了包含Fragment的Activity,你必须同时继承 FragmentActivity 类,而不是普通的 Activity 类。下节课你将会看到fragment和activity的示例代码。

posted on 2012-08-21 14:10  梵谷星辰  阅读(750)  评论(0编辑  收藏  举报

导航