1page.title=Support Package 2 3@jd:body 4 5<div id="qv-wrapper"> 6<div id="qv"> 7 8<h2>In this document</h2> 9<ol> 10 <li><a href="#Notes">Revisions</a></li> 11 <li><a href="#Downloading">Downloading the Support Package</a></li> 12 <li><a href="#SettingUp">Setting Up a Project to Use a Library</a></li> 13 <li><a href="#Using">Using the v4 Library APIs</a></li> 14 <li><a href="#Docs">Reference Docs</a></li> 15 <li><a href="#Samples">Samples</a></li> 16</ol> 17 18<h2>See also</h2> 19<ol> 20 <li><a 21href="{@docRoot}guide/practices/optimizing-for-3.0.html">Optimizing Apps for Android 3.0</a></li> 22 <li><a href="http://code.google.com/p/iosched/">Google I/O App source code</a></li> 23</ol> 24 25</div> 26</div> 27 28<p><em>Minimum API level supported:</em> <b>4</b></p> 29 30<p>The Support Package includes static "support libraries" that you can add to your Android 31application in order to use APIs that are either not available for older platform versions or that 32offer "utility" APIs that aren't a part of the framework APIs. The goal is to simplify your 33development by offering more APIs that you can bundle with your application so you can 34worry less about platform versions.</p> 35 36<p class="note"><strong>Note:</strong> The Support Package includes more than one support 37library. Each one has a different <em>minimum API level</em>. For example, one library requires API 38level 4 or higher, while another requires API level 13 or higher (v13 is a superset of v4 and includes additional 39support classes to work with v13 APIs). The minimum version is indicated 40by the directory name, such as {@code v4/} and {@code v13/}.</p> 41 42 43<h2 id="Notes">Revisions</h2> 44 45<p>The sections below provide notes about successive releases of 46the Support Package, as denoted by revision number.</p> 47 48 49 50<div class="toggle-content open"> 51 52 <p><a href="#" onclick="return toggleContent(this)"> 53 <img src="{@docRoot}assets/images/triangle-opened.png" class="toggle-content-img" /> 54 Support Package, revision 4 (October 2011) 55 </a></p> 56 57 <div class="toggle-content-toggleme" style="padding-left:2em"> 58 <dl> 59 <dt>Changes for v4 support library:</dt> 60 <dd> 61 <ul> 62 <li>Support for Accessiblity APIs: 63 <ul> 64 <li>Added <code>AccessibilityDelegateCompat</code> to support 65 {@link android.view.View.AccessibilityDelegate}.</li> 66 67 <li>Added <code>AccessibilityEventCompat</code> to support 68 {@link android.view.accessibility.AccessibilityEvent}.</li> 69 70 <li>Added <code>AccessibilityManagerCompat</code> to support 71 {@link android.view.accessibility.AccessibilityManager}.</li> 72 73 <li>Added <code>AccessibilityNodeInfoCompat</code> to support 74 {@link android.view.accessibility.AccessibilityNodeInfo}.</li> 75 76 <li>Added <code>AccessibilityRecordCompat</code> to support 77 {@link android.view.accessibility.AccessibilityRecord}.</li> 78 79 <li>Added <code>AccessibilityServiceInfoCompat</code> to support 80 {@link android.accessibilityservice.AccessibilityServiceInfo}.</li> 81 82 <li>Added <code>ViewGroupCompat</code> 83 to support accessibility features in {@link android.view.ViewGroup}. 84 </li> 85 86 <li>Modified <code>ViewCompat</code> 87 to support accessibility features in {@link android.view.View}.</li> 88 </ul> 89 </li> 90 91 <li>Added <code>EdgeEffectCompat</code> to 92 support {@link android.widget.EdgeEffect}.</li> 93 94 <li>Added <code>LocalBroadcastManager</code> to allow applications to easily 95 register for and receive intents within a single application without 96 broadcasting them globally.</li> 97 98 <li>Added support in <code>ViewCompat</code> to check for and set overscroll 99 modes for {@link android.view.View}s on Android 2.3 and later.</li> 100 <li>Changes to Fragment APIs: 101 <ul> 102 <li>Added new APIs to control the visibility of new menus.</li> 103 <li>Added custom animation APIs.</li> 104 <li>Added APIs in <code>FragmentActivity</code> to retain custom, 105 non-configuration instance data.</li> 106 <li>Various bug fixes.</li> 107 </ul> 108 </li> 109 <li>Changes to <code>ViewPager</code>: 110 <ul> 111 <li>Added support for margins between pages. 112 An optional {@link android.graphics.drawable.Drawable} can be provided 113 to fill the margins.</li> 114 <li>Added support for {@link android.widget.EdgeEffect}.</li> 115 <li>Added support for keyboard navigation</li> 116 <li>Added support to control how many pages are kept to either side 117 of the current page.</li> 118 <li>Improved touch physics.</li> 119 </ul> 120 </li> 121 122 <li>Fixed a {@link android.content.Loader} bug that caused issues in 123 canceling {@link android.os.AsyncTask}s when running on Froyo and older 124 versions of the platform. The support 125 code now uses its own version of {@link android.os.AsyncTask} to keep the same 126 behavior on all platform versions.</li> 127 128 </ul> 129 </dd> 130 </dl> 131 </div> 132 133 134 135</div> 136 137 138<div class="toggle-content closed"> 139 140 <p><a href="#" onclick="return toggleContent(this)"> 141 <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" /> 142 Compatibility Package, revision 3 (July 2011) 143 </a></p> 144 145 <div class="toggle-content-toggleme" style="padding-left:2em"> 146 <dl> 147 <dt>Changes for v4 support library:</dt> 148 <dd> 149 <ul> 150 <li>Adds support for {@link android.app.Fragment.SavedState}</li> 151 <li>Adds {@code MotionEventCompat} to support newer {@link 152android.view.MotionEvent} APIs</li> 153 <li>Adds {@code VelocityTrackerCompat} to support a newer {@link 154android.view.VelocityTracker} APIs</li> 155 <li>Adds {@code ViewConfigurationCompat} to support a newer {@link 156android.view.ViewConfiguration} APIs</li> 157 <li>All new APIs (available only in the support library) that allow you to create UIs 158with horizontal paging, allowing users to swipe left and right between content views. Classes to 159support this include: 160 <ul> 161 <li>{@code ViewPager}: A {@link android.view.ViewGroup} that manages the 162layout for the child views, which the user can swipe between.</li> 163 <li>{@code PagerAdapter}: An adapter that populates the {@code ViewPager} with the 164views that represent each page.</li> 165 <li>{@code FragmentPagerAdapter}: An extension of {@code PagerAdapter} for flipping 166between fragments.</li> 167 <li>{@code FragmentStatePagerAdapter}: An extension of {@code PagerAdapter} for 168flipping between fragments that uses the library's support for {@link 169android.app.Fragment.SavedState}.</li> 170 </ul> 171 </li> 172 </ul> 173 </dd> 174 <dt>New v13 support library:</dt> 175 <dd> 176 <ul> 177 <li>Includes the {@code FragmentPagerAdapter} and {@code FragmentStatePagerAdapter} 178to support the horizontal paging. 179 <p>These are exactly the same as the APIs added to the v4 support library, but rely on 180other platform components in Android 3.2. Use this library instead of v4 if you're developing for 181Android 3.2 and higher (all other APIs in the v4 library are already available with API level 18213).</p> 183 </li> 184 </ul> 185 </dd> 186 </dl> 187 </div> 188 189</div> 190 191 192<div class="toggle-content closed"> 193 194 <p><a href="#" onclick="return toggleContent(this)"> 195 <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" /> 196 Compatibility Package, revision 2 (May 2011) 197 </a></p> 198 199 <div class="toggle-content-toggleme" style="padding-left:2em"> 200 <dl> 201 <dt>Changes for v4 library:</dt> 202 <dd> 203 <ul> 204 <li>Support for fragment animations</li> 205 <li>Fix {@code Fragment.onActivityResult()} bug</li> 206 </ul> 207 </dd> 208 </dl> 209 </div> 210 211</div> 212 213 214<div class="toggle-content closed"> 215 216 <p><a href="#" onclick="return toggleContent(this)"> 217 <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" /> 218 Compatibility Package, revision 1 (March 2011) 219 </a></p> 220 221 <div class="toggle-content-toggleme" style="padding-left:2em"> 222 <p>Initial release with the v4 library.</p> 223 </div> 224 225</div> 226 227 228 229<h2 id="Downloading">Downloading the Support Package</h2> 230 231<p>The Support Package is provided as a downloadable package from the Android SDK and AVD 232Manager. To install:</p> 233 234<ol> 235 <li>Launch the SDK and AVD Manager. 236 <p>From Eclipse, you can select <strong>Window</strong> 237> <strong>Android SDK and AVD Manager</strong>. Or, launch {@code SDK Manager.exe} from 238the {@code <sdk>/} directory (on Windows only) or {@code android} from the {@code 239<sdk>/tools/} directory.</p></li> 240 <li>Expand the Android Repository, check <strong>Android Support package</strong> 241and click <strong>Install selected</strong>.</li> 242 <li>Proceed to install the package.</li> 243</ol> 244 245<p>When done, all files (including source code, samples, and the {@code .jar} files) are saved 246into the <code><sdk>/extras/android/support/</code> directory. This directory contains 247each of the different support libraries, such as the library for API level 4 and up and the library 248for API level 13 and up, each named with the respective version (such as {@code v4/}).</p> 249 250 251<h2 id="SettingUp">Setting Up a Project to Use a Library</h2> 252 253<p>To add one of the libraries to your Android project:</p> 254<ol> 255 <li>In your Android project, create a directory named {@code libs} at the root of your 256project (next to {@code src/}, {@code res/}, etc.)</li> 257 <li>Locate the JAR file for the library you want to use and copy it into the {@code 258libs/} directory. 259 <p>For example, the library that supports API level 4 and up is located at {@code 260<sdk>/extras/android/support/v4/android-support-v4.jar}.</p> 261 </li> 262 <li>Add the JAR to your project build path. 263 <p>In Eclipse, right-click the JAR file in the Package Explorer, select <strong>Build 264Path</strong> > <strong>Add to Build Path</strong>. You should then see the JAR file appear in a 265new directory called Referenced Libraries.</p> 266 </li> 267</ol> 268 269<p>Your application is now ready to use the library APIs. All the 270provided APIs are available in the {@code android.support} package (for 271example, {@code android.support.v4}).</p> 272 273<p class="note"><strong>Tip:</strong> To see the library APIs in action, take a look at the sample 274apps in {@code extras/android/support/<version>/samples/}.</p> 275 276<p class="warning"><strong>Warning:</strong> Be certain that you not confuse the standard 277{@code android} packages with those in {@code android.support} library. Some code completion tools 278might 279get this wrong, especially if you're building against recent versions of the platform. To be safe, 280keep your build target set to the same version as you have defined for your <a 281href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code android:minSdkVersion}</a> 282and double check the import statements for classes that also exist in the support library, such as 283{@code SimpleCursorAdapter}.</p> 284 285 286<h2 id="Using">Using the v4 Library APIs</h2> 287 288<p>The support library for v4 provides access to several classes introduced with Android 3.0 and 289beyond, plus some updated version of existing classes, and even some APIs that currently don't 290exist in the Android platform. Some of the most useful and notable classes that have 291counterparts in the v4 support library are:</p> 292 293<ul> 294 <li>{@link android.app.Fragment}</li> 295 <li>{@link android.app.FragmentManager}</li> 296 <li>{@link android.app.FragmentTransaction}</li> 297 <li>{@link android.app.ListFragment}</li> 298 <li>{@link android.app.DialogFragment}</li> 299 <li>{@link android.app.LoaderManager}</li> 300 <li>{@link android.content.Loader}</li> 301 <li>{@link android.content.AsyncTaskLoader}</li> 302 <li>{@link android.content.CursorLoader}</li> 303</ul> 304 305<p>For each of the classes above (and others not listed), the APIs work almost exactly the same 306as the counterparts in the latest Android platform. Thus, you can usually refer to 307the online documentation for information about the supported APIs. There are some 308differences, however. Most notably:</p> 309 310<ul> 311 <li>When creating an activity to use fragments, you must declare your activity to extend the 312{@code FragmentActivity} class (instead of the traditional {@link android.app.Activity} 313class).</li> 314 <li>To manage your fragments and loaders, you must use the methods {@code 315FragmentActivity.getSupportFragmentManager()} and {@code 316FragmentActivity.getSupportLoaderManager()} (instead of the {@link 317android.app.Activity#getFragmentManager()} and {@link android.app.Activity#getLoaderManager()} 318methods).</li> 319 <li>The {@link android.app.ActionBar} is <strong>not supported</strong> by the library. 320However, when creating your <a href="{@docRoot}guide/topics/ui/menus.html#options-menu">Options 321Menu</a>, you can declare which items should be added to the Action Bar when it's available (on 322Android 3.0 or later). You can do so with the {@code MenuCompat.setShowAsAction()} method. For 323example: 324<pre> 325public boolean onCreateOptionsMenu(Menu menu) { 326 MenuInflater inflater = getMenuInflater(); 327 inflater.inflate(R.menu.options, menu); 328 MenuCompat.setShowAsAction(menu.findItem(R.id.action_search), 1); 329 return true; 330} 331</pre> 332</li> 333</ul> 334 335<div class="note"><p><strong>Tip:</strong> To enable the Holographic theme on devices 336running Android 3.0 or higher, declare in your manifest file that your application targets 337API level 11. For example:</p> 338<pre> 339<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11" /> 340</pre> 341<p>This way, your application automatically receives the Holographic theme and the Action Bar for 342each activity when running on Android 3.0 and higher.</p> 343</div> 344 345<p>For more information about how you can optimize your application for the latest 346Android-powered devices, read <a href="{@docRoot}guide/practices/optimizing-for-3.0.html">Optimizing 347Apps for Android 3.0</a>.</p> 348 349 350<h2 id="Docs">Reference Docs</h2> 351 352<p>The libraries currently do not provide reference documentation for the included APIs. To generate 353your own set using the {@code javadoc} tool, perform the following from a command (as appropriate 354for the library version you're using). In this example, documentation is generated for the v4 355library:</p> 356 357<pre class="no-pretty-print"> 358cd <sdk>/extras/android/support/v4/ 359mkdir docs 360javadoc -sourcepath src/java/ -subpackages android.support.v4 -d docs 361</pre> 362<p>Open the {@code docs/index.html} file to begin browsing the generated documentation.</p> 363 364 365<h2 id="Samples">Samples</h2> 366 367<p>If you want to see some code that uses the support libraries, samples are included with the 368Support Package, inside each support library directory. For example, at {@code 369extras/android/support/v4/samples/}.</p> 370 371<p>Additionally, the <a href="http://code.google.com/p/iosched/">Google I/O App</a> is a complete 372application that uses the v4 support library to provide a single APK for both handsets and tablets 373and also demonstrates some of Android's best practices in Android UI design.</p> 374 375 376 377 378