blob: 0ef5770828dfed0ccc2a21789636043cc5efe6f0 [file] [log] [blame]
Robert Ly8db858f2011-10-18 13:30:47 -07001page.title=Support Package
Scott Main28fb09e2011-05-23 17:27:17 -07002
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>
Robert Ly8db858f2011-10-18 13:30:47 -070011 <li><a href="#Downloading">Downloading the Support Package</a></li>
Scott Mainaecaf932011-07-14 10:01:42 -070012 <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>
Scott Main28fb09e2011-05-23 17:27:17 -070015 <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
Robert Ly8db858f2011-10-18 13:30:47 -070030<p>The Support Package includes static "support libraries" that you can add to your Android
Scott Mainaecaf932011-07-14 10:01:42 -070031application 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
Scott Mainffcbe482011-07-15 09:50:49 -070033development by offering more APIs that you can bundle with your application so you can
Scott Mainaecaf932011-07-14 10:01:42 -070034worry less about platform versions.</p>
Scott Main28fb09e2011-05-23 17:27:17 -070035
Robert Ly8db858f2011-10-18 13:30:47 -070036<p class="note"><strong>Note:</strong> The Support Package includes more than one support
Scott Mainffcbe482011-07-15 09:50:49 -070037library. Each one has a different <em>minimum API level</em>. For example, one library requires API
Robert Ly8db858f2011-10-18 13:30:47 -070038level 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
Scott Mainffcbe482011-07-15 09:50:49 -070040by the directory name, such as {@code v4/} and {@code v13/}.</p>
Scott Main28fb09e2011-05-23 17:27:17 -070041
42
43<h2 id="Notes">Revisions</h2>
44
45<p>The sections below provide notes about successive releases of
Robert Ly8db858f2011-10-18 13:30:47 -070046the Support Package, as denoted by revision number.</p>
47
Scott Main28fb09e2011-05-23 17:27:17 -070048
Scott Main28fb09e2011-05-23 17:27:17 -070049<div class="toggle-content open">
50
51 <p><a href="#" onclick="return toggleContent(this)">
52 <img src="{@docRoot}assets/images/triangle-opened.png" class="toggle-content-img" />
Joe Fernandeze4f20312011-12-15 13:23:53 -080053 Support Package, revision 6 (December 2011)
54 </a></p>
55
56 <div class="toggle-content-toggleme" style="padding-left:2em">
57 <dl>
58 <dt>Changes for v4 support library:</dt>
59 <dd>
60 <ul>
61 <li>Changes to ViewPager:
62 <ul>
63 <li>Added extra decorative view support for {@link android.support.v4.view.ViewPager}.
64 Decorative views may be supplied as child views of a pager in XML layout.</li>
65 <li>Added {@link android.support.v4.view.PagerAdapter#getPageTitle
66 PagerAdapter.getPageTitle()} to supply title strings for pages, which defaults to no
67 title for each page.</li>
68 <li>Added {@link android.support.v4.view.PagerTitleStrip}, a non-interactive title
69 strip, that can be added as a child of ViewPager. Developers can supply text
70 appearance and color, as well as layout sizing and gravity information.</li>
71 <li>Updated PagerAdapter methods to take ViewGroup objects, rather than View to avoid
72 class casting in adapter implementations. For more information, see
73 {@link android.support.v4.view.PagerAdapter}.</li>
74 <li>Updated ViewPager to use Launcher Workspace-style fling behavior.</li>
75 <li>Bug fixes for user interface interaction and test automation.</li>
76 </ul>
77 </li>
78
79 <li>Support for Fragments:
80 <ul>
81 <li>Changed {@code setStartDeferred()} method to {@link
82 android.support.v4.app.Fragment#setUserVisibleHint}.</li>
83 <li>Added deferred start for off-screen pages to improve performance.</li>
84 </ul>
85 </li>
86
87 <li>Support for Accessiblity APIs:
88 <ul>
89 <li>Updated {@link android.support.v4.view.AccessibilityDelegateCompat} methods
90 to return empty lists instead of null.</li>
91 <li>Added new APIs needed by the v4 samples.</li>
92 </ul>
93 </li>
94
95 </ul>
96 </dd>
97 </dl>
98 </div>
99
100<div class="toggle-content closed">
101
102 <p><a href="#" onclick="return toggleContent(this)">
103 <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" />
104 Support Package, revision 5 (December 2011)
Robert Ly8db858f2011-10-18 13:30:47 -0700105 </a></p>
106
107 <div class="toggle-content-toggleme" style="padding-left:2em">
108 <dl>
109 <dt>Changes for v4 support library:</dt>
110 <dd>
111 <ul>
112 <li>Support for Accessiblity APIs:
113 <ul>
114 <li>Added <code>AccessibilityDelegateCompat</code> to support
115 {@link android.view.View.AccessibilityDelegate}.</li>
116
117 <li>Added <code>AccessibilityEventCompat</code> to support
118 {@link android.view.accessibility.AccessibilityEvent}.</li>
119
120 <li>Added <code>AccessibilityManagerCompat</code> to support
121 {@link android.view.accessibility.AccessibilityManager}.</li>
122
123 <li>Added <code>AccessibilityNodeInfoCompat</code> to support
124 {@link android.view.accessibility.AccessibilityNodeInfo}.</li>
125
126 <li>Added <code>AccessibilityRecordCompat</code> to support
127 {@link android.view.accessibility.AccessibilityRecord}.</li>
128
129 <li>Added <code>AccessibilityServiceInfoCompat</code> to support
130 {@link android.accessibilityservice.AccessibilityServiceInfo}.</li>
131
132 <li>Added <code>ViewGroupCompat</code>
133 to support accessibility features in {@link android.view.ViewGroup}.
134 </li>
135
136 <li>Modified <code>ViewCompat</code>
137 to support accessibility features in {@link android.view.View}.</li>
138 </ul>
139 </li>
140
Joe Fernandeze4f20312011-12-15 13:23:53 -0800141 <li>Changes to <code>ViewPager</code>:
142 <ul>
143 <li>Added support for margins between pages.
144 An optional {@link android.graphics.drawable.Drawable} can be provided
145 to fill the margins.</li>
146 <li>Added support for {@link android.widget.EdgeEffect}.</li>
147 <li>Added support for keyboard navigation</li>
148 <li>Added support to control how many pages are kept to either side
149 of the current page.</li>
150 <li>Improved touch physics.</li>
151 <li>Bug fixes for user interface behavior.</li>
152 </ul>
153 </li>
154 </ul>
155 </dd>
156 </dl>
157 </div>
158
159<div class="toggle-content closed">
160
161 <p><a href="#" onclick="return toggleContent(this)">
162 <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" />
163 Support Package, revision 4 (October 2011)
164 </a></p>
165
166 <div class="toggle-content-toggleme" style="padding-left:2em">
167 <dl>
168 <dt>Changes for v4 support library:</dt>
169 <dd>
170 <ul>
Robert Ly8db858f2011-10-18 13:30:47 -0700171 <li>Added <code>EdgeEffectCompat</code> to
172 support {@link android.widget.EdgeEffect}.</li>
173
174 <li>Added <code>LocalBroadcastManager</code> to allow applications to easily
175 register for and receive intents within a single application without
176 broadcasting them globally.</li>
177
178 <li>Added support in <code>ViewCompat</code> to check for and set overscroll
179 modes for {@link android.view.View}s on Android 2.3 and later.</li>
180 <li>Changes to Fragment APIs:
181 <ul>
182 <li>Added new APIs to control the visibility of new menus.</li>
183 <li>Added custom animation APIs.</li>
184 <li>Added APIs in <code>FragmentActivity</code> to retain custom,
185 non-configuration instance data.</li>
186 <li>Various bug fixes.</li>
187 </ul>
188 </li>
Joe Fernandeze4f20312011-12-15 13:23:53 -0800189
Robert Ly8db858f2011-10-18 13:30:47 -0700190 <li>Fixed a {@link android.content.Loader} bug that caused issues in
191 canceling {@link android.os.AsyncTask}s when running on Froyo and older
192 versions of the platform. The support
193 code now uses its own version of {@link android.os.AsyncTask} to keep the same
194 behavior on all platform versions.</li>
195
196 </ul>
197 </dd>
198 </dl>
199 </div>
200
201
202
203</div>
204
205
206<div class="toggle-content closed">
207
208 <p><a href="#" onclick="return toggleContent(this)">
209 <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" />
Scott Mainaecaf932011-07-14 10:01:42 -0700210 Compatibility Package, revision 3 (July 2011)
Scott Main28fb09e2011-05-23 17:27:17 -0700211 </a></p>
212
213 <div class="toggle-content-toggleme" style="padding-left:2em">
214 <dl>
Scott Mainaecaf932011-07-14 10:01:42 -0700215 <dt>Changes for v4 support library:</dt>
216 <dd>
217 <ul>
218 <li>Adds support for {@link android.app.Fragment.SavedState}</li>
219 <li>Adds {@code MotionEventCompat} to support newer {@link
220android.view.MotionEvent} APIs</li>
221 <li>Adds {@code VelocityTrackerCompat} to support a newer {@link
222android.view.VelocityTracker} APIs</li>
223 <li>Adds {@code ViewConfigurationCompat} to support a newer {@link
224android.view.ViewConfiguration} APIs</li>
225 <li>All new APIs (available only in the support library) that allow you to create UIs
Scott Mainffcbe482011-07-15 09:50:49 -0700226with horizontal paging, allowing users to swipe left and right between content views. Classes to
227support this include:
Scott Mainaecaf932011-07-14 10:01:42 -0700228 <ul>
229 <li>{@code ViewPager}: A {@link android.view.ViewGroup} that manages the
230layout for the child views, which the user can swipe between.</li>
231 <li>{@code PagerAdapter}: An adapter that populates the {@code ViewPager} with the
232views that represent each page.</li>
233 <li>{@code FragmentPagerAdapter}: An extension of {@code PagerAdapter} for flipping
234between fragments.</li>
Scott Mainffcbe482011-07-15 09:50:49 -0700235 <li>{@code FragmentStatePagerAdapter}: An extension of {@code PagerAdapter} for
236flipping between fragments that uses the library's support for {@link
237android.app.Fragment.SavedState}.</li>
Scott Mainaecaf932011-07-14 10:01:42 -0700238 </ul>
239 </li>
240 </ul>
241 </dd>
242 <dt>New v13 support library:</dt>
243 <dd>
244 <ul>
245 <li>Includes the {@code FragmentPagerAdapter} and {@code FragmentStatePagerAdapter}
246to support the horizontal paging.
247 <p>These are exactly the same as the APIs added to the v4 support library, but rely on
248other platform components in Android 3.2. Use this library instead of v4 if you're developing for
249Android 3.2 and higher (all other APIs in the v4 library are already available with API level
25013).</p>
251 </li>
252 </ul>
253 </dd>
254 </dl>
255 </div>
256
257</div>
258
259
260<div class="toggle-content closed">
261
262 <p><a href="#" onclick="return toggleContent(this)">
263 <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" />
264 Compatibility Package, revision 2 (May 2011)
265 </a></p>
266
267 <div class="toggle-content-toggleme" style="padding-left:2em">
268 <dl>
269 <dt>Changes for v4 library:</dt>
Scott Main28fb09e2011-05-23 17:27:17 -0700270 <dd>
271 <ul>
Scott Mainaecaf932011-07-14 10:01:42 -0700272 <li>Support for fragment animations</li>
Joe Fernandeze4f20312011-12-15 13:23:53 -0800273 <li>Fix {@code android.support.v4.app.Fragment#onActivityResult Fragment.onActivityResult()}
274 bug</li>
Scott Main28fb09e2011-05-23 17:27:17 -0700275 </ul>
276 </dd>
277 </dl>
278 </div>
279
280</div>
281
282
283<div class="toggle-content closed">
284
285 <p><a href="#" onclick="return toggleContent(this)">
286 <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" />
Scott Mainaecaf932011-07-14 10:01:42 -0700287 Compatibility Package, revision 1 (March 2011)
Scott Main28fb09e2011-05-23 17:27:17 -0700288 </a></p>
289
290 <div class="toggle-content-toggleme" style="padding-left:2em">
Scott Mainaecaf932011-07-14 10:01:42 -0700291 <p>Initial release with the v4 library.</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700292 </div>
293
294</div>
295
296
297
Robert Ly8db858f2011-10-18 13:30:47 -0700298<h2 id="Downloading">Downloading the Support Package</h2>
Scott Main28fb09e2011-05-23 17:27:17 -0700299
Robert Ly8db858f2011-10-18 13:30:47 -0700300<p>The Support Package is provided as a downloadable package from the Android SDK and AVD
Scott Mainaecaf932011-07-14 10:01:42 -0700301Manager. To install:</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700302
303<ol>
304 <li>Launch the SDK and AVD Manager.
305 <p>From Eclipse, you can select <strong>Window</strong>
306&gt; <strong>Android SDK and AVD Manager</strong>. Or, launch {@code SDK Manager.exe} from
307the {@code &lt;sdk&gt;/} directory (on Windows only) or {@code android} from the {@code
308&lt;sdk&gt;/tools/} directory.</p></li>
Robert Ly8db858f2011-10-18 13:30:47 -0700309 <li>Expand the Android Repository, check <strong>Android Support package</strong>
Scott Main28fb09e2011-05-23 17:27:17 -0700310and click <strong>Install selected</strong>.</li>
311 <li>Proceed to install the package.</li>
312</ol>
313
Scott Mainaecaf932011-07-14 10:01:42 -0700314<p>When done, all files (including source code, samples, and the {@code .jar} files) are saved
Robert Ly8db858f2011-10-18 13:30:47 -0700315into the <code>&lt;sdk&gt;/extras/android/support/</code> directory. This directory contains
Scott Mainaecaf932011-07-14 10:01:42 -0700316each of the different support libraries, such as the library for API level 4 and up and the library
317for API level 13 and up, each named with the respective version (such as {@code v4/}).</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700318
319
Scott Mainaecaf932011-07-14 10:01:42 -0700320<h2 id="SettingUp">Setting Up a Project to Use a Library</h2>
Scott Main28fb09e2011-05-23 17:27:17 -0700321
Scott Mainaecaf932011-07-14 10:01:42 -0700322<p>To add one of the libraries to your Android project:</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700323<ol>
324 <li>In your Android project, create a directory named {@code libs} at the root of your
325project (next to {@code src/}, {@code res/}, etc.)</li>
Scott Mainaecaf932011-07-14 10:01:42 -0700326 <li>Locate the JAR file for the library you want to use and copy it into the {@code
327libs/} directory.
328 <p>For example, the library that supports API level 4 and up is located at {@code
Robert Ly8db858f2011-10-18 13:30:47 -0700329&lt;sdk&gt;/extras/android/support/v4/android-support-v4.jar}.</p>
Scott Mainaecaf932011-07-14 10:01:42 -0700330 </li>
331 <li>Add the JAR to your project build path.
332 <p>In Eclipse, right-click the JAR file in the Package Explorer, select <strong>Build
Joe Fernandeze4f20312011-12-15 13:23:53 -0800333Path</strong> &gt; <strong>Add to Build Path</strong>.</p>
Scott Mainaecaf932011-07-14 10:01:42 -0700334 </li>
Scott Main28fb09e2011-05-23 17:27:17 -0700335</ol>
336
Scott Mainaecaf932011-07-14 10:01:42 -0700337<p>Your application is now ready to use the library APIs. All the
338provided APIs are available in the {@code android.support} package (for
339example, {@code android.support.v4}).</p>
340
341<p class="note"><strong>Tip:</strong> To see the library APIs in action, take a look at the sample
Robert Ly8db858f2011-10-18 13:30:47 -0700342apps in {@code extras/android/support/&lt;version&gt;/samples/}.</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700343
344<p class="warning"><strong>Warning:</strong> Be certain that you not confuse the standard
Scott Mainaecaf932011-07-14 10:01:42 -0700345{@code android} packages with those in {@code android.support} library. Some code completion tools
346might
Scott Main28fb09e2011-05-23 17:27:17 -0700347get this wrong, especially if you're building against recent versions of the platform. To be safe,
348keep your build target set to the same version as you have defined for your <a
349href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code android:minSdkVersion}</a>
Scott Mainaecaf932011-07-14 10:01:42 -0700350and double check the import statements for classes that also exist in the support library, such as
351{@code SimpleCursorAdapter}.</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700352
353
Scott Mainaecaf932011-07-14 10:01:42 -0700354<h2 id="Using">Using the v4 Library APIs</h2>
Scott Main28fb09e2011-05-23 17:27:17 -0700355
Scott Mainaecaf932011-07-14 10:01:42 -0700356<p>The support library for v4 provides access to several classes introduced with Android 3.0 and
357beyond, plus some updated version of existing classes, and even some APIs that currently don't
358exist in the Android platform. Some of the most useful and notable classes that have
359counterparts in the v4 support library are:</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700360
361<ul>
362 <li>{@link android.app.Fragment}</li>
363 <li>{@link android.app.FragmentManager}</li>
364 <li>{@link android.app.FragmentTransaction}</li>
365 <li>{@link android.app.ListFragment}</li>
366 <li>{@link android.app.DialogFragment}</li>
367 <li>{@link android.app.LoaderManager}</li>
368 <li>{@link android.content.Loader}</li>
369 <li>{@link android.content.AsyncTaskLoader}</li>
370 <li>{@link android.content.CursorLoader}</li>
371</ul>
372
373<p>For each of the classes above (and others not listed), the APIs work almost exactly the same
Scott Mainaecaf932011-07-14 10:01:42 -0700374as the counterparts in the latest Android platform. Thus, you can usually refer to
375the online documentation for information about the supported APIs. There are some
Scott Main28fb09e2011-05-23 17:27:17 -0700376differences, however. Most notably:</p>
377
378<ul>
379 <li>When creating an activity to use fragments, you must declare your activity to extend the
380{@code FragmentActivity} class (instead of the traditional {@link android.app.Activity}
381class).</li>
382 <li>To manage your fragments and loaders, you must use the methods {@code
383FragmentActivity.getSupportFragmentManager()} and {@code
384FragmentActivity.getSupportLoaderManager()} (instead of the {@link
385android.app.Activity#getFragmentManager()} and {@link android.app.Activity#getLoaderManager()}
386methods).</li>
387 <li>The {@link android.app.ActionBar} is <strong>not supported</strong> by the library.
388However, when creating your <a href="{@docRoot}guide/topics/ui/menus.html#options-menu">Options
389Menu</a>, you can declare which items should be added to the Action Bar when it's available (on
390Android 3.0 or later). You can do so with the {@code MenuCompat.setShowAsAction()} method. For
391example:
392<pre>
393public boolean onCreateOptionsMenu(Menu menu) {
394 MenuInflater inflater = getMenuInflater();
395 inflater.inflate(R.menu.options, menu);
396 MenuCompat.setShowAsAction(menu.findItem(R.id.action_search), 1);
397 return true;
398}
399</pre>
400</li>
401</ul>
402
Scott Main28fb09e2011-05-23 17:27:17 -0700403<div class="note"><p><strong>Tip:</strong> To enable the Holographic theme on devices
404running Android 3.0 or higher, declare in your manifest file that your application targets
405API level 11. For example:</p>
406<pre>
407&lt;uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11" /&gt;
408</pre>
409<p>This way, your application automatically receives the Holographic theme and the Action Bar for
410each activity when running on Android 3.0 and higher.</p>
411</div>
412
413<p>For more information about how you can optimize your application for the latest
414Android-powered devices, read <a href="{@docRoot}guide/practices/optimizing-for-3.0.html">Optimizing
415Apps for Android 3.0</a>.</p>
416
417
Scott Mainaecaf932011-07-14 10:01:42 -0700418<h2 id="Docs">Reference Docs</h2>
419
420<p>The libraries currently do not provide reference documentation for the included APIs. To generate
421your own set using the {@code javadoc} tool, perform the following from a command (as appropriate
422for the library version you're using). In this example, documentation is generated for the v4
423library:</p>
424
425<pre class="no-pretty-print">
Robert Ly8db858f2011-10-18 13:30:47 -0700426cd &lt;sdk&gt;/extras/android/support/v4/
Scott Mainaecaf932011-07-14 10:01:42 -0700427mkdir docs
428javadoc -sourcepath src/java/ -subpackages android.support.v4 -d docs
429</pre>
430<p>Open the {@code docs/index.html} file to begin browsing the generated documentation.</p>
431
432
Scott Main28fb09e2011-05-23 17:27:17 -0700433<h2 id="Samples">Samples</h2>
434
Scott Mainaecaf932011-07-14 10:01:42 -0700435<p>If you want to see some code that uses the support libraries, samples are included with the
Robert Ly8db858f2011-10-18 13:30:47 -0700436Support Package, inside each support library directory. For example, at {@code
437extras/android/support/v4/samples/}.</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700438
439<p>Additionally, the <a href="http://code.google.com/p/iosched/">Google I/O App</a> is a complete
Scott Mainaecaf932011-07-14 10:01:42 -0700440application that uses the v4 support library to provide a single APK for both handsets and tablets
441and also demonstrates some of Android's best practices in Android UI design.</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700442
443
444
445