Using the Support Library

使用Android支持库
本文介绍如何设置项目以使用Android支持库来实现Fragment功能,并适用于较旧版本的Android系统。通过下载支持包并更新manifest文件,开发者可在Android 1.6及以上版本中利用最新的API特性。

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.

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.

Set Up Your Project With the Support Library


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

To set up your project:

  1. Downlad 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" />

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.

You can find all the API reference documentation for the Support Library in the platform docs at 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.app package:

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值