blob: 8b19fb47aa1267c85b28c4748ee8d72167738b5b [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
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" />
Robert Ly8db858f2011-10-18 13:30:47 -070054 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" />
Scott Mainaecaf932011-07-14 10:01:42 -0700142 Compatibility Package, revision 3 (July 2011)
Scott Main28fb09e2011-05-23 17:27:17 -0700143 </a></p>
144
145 <div class="toggle-content-toggleme" style="padding-left:2em">
146 <dl>
Scott Mainaecaf932011-07-14 10:01:42 -0700147 <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
Scott Mainffcbe482011-07-15 09:50:49 -0700158with horizontal paging, allowing users to swipe left and right between content views. Classes to
159support this include:
Scott Mainaecaf932011-07-14 10:01:42 -0700160 <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>
Scott Mainffcbe482011-07-15 09:50:49 -0700167 <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>
Scott Mainaecaf932011-07-14 10:01:42 -0700170 </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>
Scott Main28fb09e2011-05-23 17:27:17 -0700202 <dd>
203 <ul>
Scott Mainaecaf932011-07-14 10:01:42 -0700204 <li>Support for fragment animations</li>
205 <li>Fix {@code Fragment.onActivityResult()} bug</li>
Scott Main28fb09e2011-05-23 17:27:17 -0700206 </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" />
Scott Mainaecaf932011-07-14 10:01:42 -0700218 Compatibility Package, revision 1 (March 2011)
Scott Main28fb09e2011-05-23 17:27:17 -0700219 </a></p>
220
221 <div class="toggle-content-toggleme" style="padding-left:2em">
Scott Mainaecaf932011-07-14 10:01:42 -0700222 <p>Initial release with the v4 library.</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700223 </div>
224
225</div>
226
227
228
Robert Ly8db858f2011-10-18 13:30:47 -0700229<h2 id="Downloading">Downloading the Support Package</h2>
Scott Main28fb09e2011-05-23 17:27:17 -0700230
Robert Ly8db858f2011-10-18 13:30:47 -0700231<p>The Support Package is provided as a downloadable package from the Android SDK and AVD
Scott Mainaecaf932011-07-14 10:01:42 -0700232Manager. To install:</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700233
234<ol>
235 <li>Launch the SDK and AVD Manager.
236 <p>From Eclipse, you can select <strong>Window</strong>
237&gt; <strong>Android SDK and AVD Manager</strong>. Or, launch {@code SDK Manager.exe} from
238the {@code &lt;sdk&gt;/} directory (on Windows only) or {@code android} from the {@code
239&lt;sdk&gt;/tools/} directory.</p></li>
Robert Ly8db858f2011-10-18 13:30:47 -0700240 <li>Expand the Android Repository, check <strong>Android Support package</strong>
Scott Main28fb09e2011-05-23 17:27:17 -0700241and click <strong>Install selected</strong>.</li>
242 <li>Proceed to install the package.</li>
243</ol>
244
Scott Mainaecaf932011-07-14 10:01:42 -0700245<p>When done, all files (including source code, samples, and the {@code .jar} files) are saved
Robert Ly8db858f2011-10-18 13:30:47 -0700246into the <code>&lt;sdk&gt;/extras/android/support/</code> directory. This directory contains
Scott Mainaecaf932011-07-14 10:01:42 -0700247each 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>
Scott Main28fb09e2011-05-23 17:27:17 -0700249
250
Scott Mainaecaf932011-07-14 10:01:42 -0700251<h2 id="SettingUp">Setting Up a Project to Use a Library</h2>
Scott Main28fb09e2011-05-23 17:27:17 -0700252
Scott Mainaecaf932011-07-14 10:01:42 -0700253<p>To add one of the libraries to your Android project:</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700254<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>
Scott Mainaecaf932011-07-14 10:01:42 -0700257 <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
Robert Ly8db858f2011-10-18 13:30:47 -0700260&lt;sdk&gt;/extras/android/support/v4/android-support-v4.jar}.</p>
Scott Mainaecaf932011-07-14 10:01:42 -0700261 </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> &gt; <strong>Add to Build Path</strong>. You should then see the JAR file appear in a
265new directory called Referenced Libraries.</p>
266 </li>
Scott Main28fb09e2011-05-23 17:27:17 -0700267</ol>
268
Scott Mainaecaf932011-07-14 10:01:42 -0700269<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
Robert Ly8db858f2011-10-18 13:30:47 -0700274apps in {@code extras/android/support/&lt;version&gt;/samples/}.</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700275
276<p class="warning"><strong>Warning:</strong> Be certain that you not confuse the standard
Scott Mainaecaf932011-07-14 10:01:42 -0700277{@code android} packages with those in {@code android.support} library. Some code completion tools
278might
Scott Main28fb09e2011-05-23 17:27:17 -0700279get 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>
Scott Mainaecaf932011-07-14 10:01:42 -0700282and double check the import statements for classes that also exist in the support library, such as
283{@code SimpleCursorAdapter}.</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700284
285
Scott Mainaecaf932011-07-14 10:01:42 -0700286<h2 id="Using">Using the v4 Library APIs</h2>
Scott Main28fb09e2011-05-23 17:27:17 -0700287
Scott Mainaecaf932011-07-14 10:01:42 -0700288<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>
Scott Main28fb09e2011-05-23 17:27:17 -0700292
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
Scott Mainaecaf932011-07-14 10:01:42 -0700306as 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
Scott Main28fb09e2011-05-23 17:27:17 -0700308differences, 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
Scott Main28fb09e2011-05-23 17:27:17 -0700335<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&lt;uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11" /&gt;
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
Scott Mainaecaf932011-07-14 10:01:42 -0700350<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">
Robert Ly8db858f2011-10-18 13:30:47 -0700358cd &lt;sdk&gt;/extras/android/support/v4/
Scott Mainaecaf932011-07-14 10:01:42 -0700359mkdir 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
Scott Main28fb09e2011-05-23 17:27:17 -0700365<h2 id="Samples">Samples</h2>
366
Scott Mainaecaf932011-07-14 10:01:42 -0700367<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 -0700368Support Package, inside each support library directory. For example, at {@code
369extras/android/support/v4/samples/}.</p>
Scott Main28fb09e2011-05-23 17:27:17 -0700370
371<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 -0700372application 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>
Scott Main28fb09e2011-05-23 17:27:17 -0700374
375
376
377