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