1page.title=Using the Support Library 2page.tags=support library 3helpoutsWidget=true 4 5trainingnavtop=true 6 7@jd:body 8 9<div id="tb-wrapper"> 10 <div id="tb"> 11 <h2>This lesson teaches you to</h2> 12 <ol> 13 <li><a href="#Setup">Set Up Your Project with the Support Library</a></li> 14 <li><a href="#Apis">Import the Support Library APIs</a></li> 15 </ol> 16 <h2>You should also read</h2> 17 <ul> 18 <li><a href="{@docRoot}tools/support-library/index.html">Support Library</a></li> 19 </ul> 20 </div> 21</div> 22 23<p>The Android <a href="{@docRoot}tools/support-library/index.html">Support Library</a> provides a JAR 24file with an API library that allows you to use some of the more recent Android APIs in your app 25while running on earlier versions of Android. For instance, the Support Library provides a version 26of the {@link android.app.Fragment} APIs that you can use on Android 1.6 (API level 4) and 27higher.</p> 28 29<p>This lesson shows how to set up your app to use the Support Library in order to use fragments 30to build a dynamic app UI.</p> 31 32 33<h2 id="Setup">Set Up Your Project with the Support Library</h2> 34 35<div class="figure" style="width:527px"> 36<img src="{@docRoot}images/training/basics/sdk-manager.png" alt="" /> 37<p class="img-caption"><strong>Figure 1.</strong> The Android SDK Manager with the 38Android Support package selected.</p> 39</div> 40 41<p>To set up your project:</p> 42 43<ol> 44 <li>Download the Android Support package using the SDK Manager.</li> 45 46 <li>Create a <code>libs</code> directory at the top level of your Android project.</li> 47 <li>Locate the JAR file for the library you want to use and copy it into the <code>libs/</code> 48directory. 49<p>For example, the library that supports API level 4 and up is located at 50<code><sdk>/extras/android/support/v4/android-support-v4.jar</code>.</p></li> 51 <li>Update your manifest file to set the minimum API level to <code>4</code> and the target 52API level to the latest release: 53 <pre><uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" /></pre> 54 </li> 55</ol> 56 57 58<h2 id="Apis">Import the Support Library APIs</h2> 59 60<p>The Support Library includes a variety of APIs that were either added in recent versions of 61Android or don't exist in the platform at all and merely provide additional support to you when 62developing specific application features.</p> 63 64<p>You can find all the API reference documentation for the Support Library in the 65platform docs at {@link android.support.v4.app android.support.v4.*}.</p> 66 67<div class="warning"><p><strong>Warning:</strong> To be sure that you don't accidentally use new 68APIs on an older system version, be certain that you import the {@link 69android.support.v4.app.Fragment} class and related APIs from the {@link android.support.v4.app} 70package:</p> 71<pre> 72import android.support.v4.app.Fragment; 73import android.support.v4.app.FragmentManager; 74... 75</pre> 76</div> 77 78 79<p>When creating an activity that hosts fragments while using the Support Library, you must also 80extend the {@link android.support.v4.app.FragmentActivity} class instead of the traditional {@link 81android.app.Activity} class. You'll see sample code for the fragment and activity in the next 82lesson.</p> 83 84