`
yidongkaifa
  • 浏览: 4059445 次
文章分类
社区版块
存档分类
最新评论

Building a Dynamic UI with Fragments---Using the Support Library

 
阅读更多

原文地址:https://developer.android.com/training/basics/fragments/support-lib.html

------------------------------------------------------------------------------------------------------------------

The Android Support Library provides a JAR file with an API library that allows 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 Support Library提供了一个JAR文件,里面包含了一个API库,它允许你在你的app中使用一些较新的Android APIs,以便运行在较早版本的Android系统上。例如,Support Library提供了一个版本Fragment接口,你可以在Android 1.6(APL level 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.

这节课向你展示了如何使用Support Library设置你的app,以便利用框架建立一个动态的app UI。

Set Up Your Project with the Support Library —— 利用支持库建立你自己的项目


Figure 1. The Android SDK Manager with the Android Support package selected.

图1. 勾选了Android Support包的Android SDK Manager

To set up your project:

  1. Download the Android Support package using the SDK Manager.
  2. Create a libs directory at the top level of your Android project.
  3. Locate the JAR file for the library you want to use and copy it into the libs/ directory.

    For example, the library that supports API level 4 and up is located at <sdk>/extras/android/support/v4/android-support-v4.jar.

  4. Update your manifest file to set the minimum API level to 4 and the target API level to the latest release:
    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />

为了建立你的项目:

  1. 使用SDK Manager下载Android Support包。
  2. 在你的Android项目的顶层目录下创建一个libs目录。
  3. 找到你想要使用的JAR文件,然后把它粘贴到 libs/ 目录下。例如,只是API level 4及其以上的库位于<sdk>/extras/android/support/v4/android-support-v4.jar。
  4. 设置最低的API level值为4,目标API level为最新发布版本,更新你的清单文件:
    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />


Import the Support Library APIs —— 导入支持库应用程序接口


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.

Support Library包含了一系列编程接口,它们要么是在最新的Android系统中添加进来的,要么根本不存在平台上,而仅仅是在你开发特殊应用特性时提供额外的支持。

You can find all the API reference documentation for the Support Library in the platform docs at android.support.v4.*.

你可以在android.support.v4.*找到Support Library的API参考文档。

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.app package:

警告:请确保你没有在较老的系统版本上意外地使用新的APIs,确认你从android.support.v4.app包中导入了Fragment类及其相关的APIs:

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.

当你使用Support Library创建一个持有框架的activity时,你必须同时扩展FragmentActivity类,而不是传统的Activity类。你将会在下一节课看到有关框架的实例代码。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics