1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
|
page.title=Support Library
@jd:body
<div id="qv-wrapper">
<div id="qv">
<h2>In this document</h2>
<ol>
<li><a href="#Notes">Revisions</a></li>
<li><a href="#Downloading">Downloading the Support Package</a></li>
<li><a href="#SettingUp">Setting Up a Project to Use a Library</a></li>
<li><a href="#Using">Using the v4 Library APIs</a></li>
<li><a href="#Docs">Reference Docs</a></li>
<li><a href="#Samples">Samples</a></li>
</ol>
<h2>See also</h2>
<ol>
<li><a
href="{@docRoot}guide/practices/optimizing-for-3.0.html">Optimizing Apps for Android 3.0</a></li>
<li><a href="http://code.google.com/p/iosched/">Google I/O App source code</a></li>
</ol>
</div>
</div>
<p><em>Minimum API level supported:</em> <b>4</b></p>
<p>The Support Package includes static "support libraries" that you can add to your Android
application in order to use APIs that are either not available for older platform versions or that
offer "utility" APIs that aren't a part of the framework APIs. The goal is to simplify your
development by offering more APIs that you can bundle with your application so you can
worry less about platform versions.</p>
<p class="note"><strong>Note:</strong> The Support Package includes more than one support
library. Each one has a different <em>minimum API level</em>. For example, one library requires API
level 4 or higher, while another requires API level 13 or higher (v13 is a superset of v4 and
includes additional
support classes to work with v13 APIs). The minimum version is indicated
by the directory name, such as {@code v4/} and {@code v13/}.</p>
<h2 id="Notes">Revisions</h2>
<p>The sections below provide notes about successive releases of
the Support Package, as denoted by revision number.</p>
<div class="toggle-content opened">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-opened.png" class="toggle-content-img" alt=""
/>Support Package, revision 12</a> <em>(February 2013)</em>
</p>
<div class="toggle-content-toggleme">
<dl>
<dt>Changes for v4 support library:</dt>
<dd>
<ul>
<li>Improved interaction behavior for {@link android.support.v4.view.ViewPager}.</li>
<li>Fixed a bug that could cause {@link android.support.v4.view.ViewPager} to select the
wrong page.</li>
<li>Fixed use of {@link android.support.v4.view.ViewPager#removeView removeView()} method
during layout for {@link android.support.v4.view.ViewPager}.</li>
<li>Fixed issue with {@link android.support.v4.widget.SearchViewCompat} where using the
back button to dismiss does not clear the search text. This fix only applies to
host API levels 14 and higher.</li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="toggle-content closed">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""
/>Support Package, revision 11</a> <em>(November 2012)</em>
</p>
<div class="toggle-content-toggleme">
<dl>
<dt>Changes for v4 support library:</dt>
<dd>
<ul>
<li>User Interface
<ul>
<li>Added support for nested {@link android.support.v4.app.Fragment} classes.</li>
<li>Added improvements to {@link android.support.v4.app.FragmentManager} debugging.
</li>
<li>Fixed problem in {@link android.support.v4.app.FragmentTabHost} where fragment
and tab interaction could result in a {@link android.widget.ListView} state loss.
</li>
<li>Fixed issue with user-visible hint in
{@link android.support.v4.app.FragmentStatePagerAdapter}.</li>
<li>Added {@link android.support.v4.view.ViewPager.PageTransformer PageTransformer}
interface to {@link android.support.v4.view.ViewPager} to allow applications to
supply a custom transition behavior for scrolling.</li>
<li>Added new features and fixes to {@link android.support.v4.app.TaskStackBuilder}
from current release.</li>
<li>Fixed {@link android.support.v4.view.PagerTitleStrip} to correctly track the
{@link android.support.v4.view.PagerAdapter} currently in use.</li>
<li>Fixed display flickering, positioning, and text clipping problems with
{@link android.support.v4.view.PagerTitleStrip}.</li>
<li>Fixed {@link android.support.v4.view.PagerTabStrip} to properly respect padding
when drawing an underline.</li>
</ul>
</li>
<li>Accessibility
<ul>
<li>Added support for new accessibility gesture and touch event types in
{@link android.support.v4.view.accessibility.AccessibilityEventCompat}.</li>
<li>Added support for new accessibility APIs in
{@link android.support.v4.view.ViewCompat}.</li>
<li>Added support for {@link android.support.v4.view.ViewCompat#performAccessibilityAction
performAccessibilityAction()} method to {@link android.support.v4.view.ViewCompat}.
</li>
</ul>
</li>
<li>Added support for gestures with {@link android.support.v4.view.GestureDetectorCompat}.
</li>
<li>Added support for performing atomic operations on files using a new
{@link android.support.v4.util.AtomicFile} class.</li>
<li>Added support for the full set of {@code make} methods in
{@link android.support.v4.content.IntentCompat}.</li>
<li>Added {@link android.support.v4.util.LruCache#trimToSize trimToSize()} method in
{@link android.support.v4.util.LruCache} utility class.</li>
<li>Updated {@link android.support.v4.net.ConnectivityManagerCompat} to get NetworkInfo
from a {@link android.net.ConnectivityManager#CONNECTIVITY_ACTION}
broadcast.</li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="toggle-content closed">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""
/>Support Package, revision 10</a> <em>(August 2012)</em>
</p>
<div class="toggle-content-toggleme">
<dl>
<dt>Changes for v4 support library:</dt>
<dd>
<ul>
<li>Added support for notification features introduced in Android 4.1 (API level 16) with
additions to {@link android.support.v4.app.NotificationCompat}.</li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="toggle-content closed">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""
/>Support Package, revision 9</a> <em>(June 2012)</em>
</p>
<div class="toggle-content-toggleme">
<dl>
<dt>Changes for v4 support library:</dt>
<dd>
<ul>
<li>User Interface Support
<ul>
<li>Added {@link android.support.v4.view.PagerTabStrip} support, providing enhanced
functionality beyond {@link android.support.v4.view.PagerTitleStrip}.</li>
<li>Fixed various bugs for {@link android.support.v4.view.PagerTitleStrip} and
{@link android.support.v4.view.PagerTabStrip}, including {@link
android.widget.TextView#setAllCaps setAllCaps} option, title alignment,
appearance improvements, minimum width constraints and touch navigation issues.</li>
<li>Added support for {@link android.support.v4.view.ViewPager} page gutters, which
helps the {@link android.support.v4.view.ViewPager} class provide paging support for content with
a large horizontal scroll range, such as a map.</li>
<li>Fixed numerous bugs for {@link android.support.v4.view.ViewPager}, including size
and data set change problems, page positioning, user interaction, scroll tracking and keyboard
navigation problems.</li>
<li>Fixed many bugs for {@link android.support.v4.app.Fragment}, including proper
handling of {@link android.support.v4.app.Fragment#onActivityResult onActivityResult()} when
the target fragment no longer exists, dispatching selection events to invisible fragments, improved
{@link android.support.v4.app.FragmentTransaction#replace FragmentTransaction.replace()} behavior
and added better state handling for fragments being moved out of view.</li>
<li>Added support for the {@link
android.support.v4.view.ViewCompat postOnAnimation()} method in {@link
android.support.v4.view.ViewCompat}.</li>
<li>Updated {@link android.support.v4.app.NavUtils} to use Android 4.1 (API level 16)
<em>Up</em> navigation functionality when available.</li>
</ul>
</li>
<li>Accessibility
<ul>
<li>Updated accessibility support classes, including {@link
android.support.v4.view.accessibility.AccessibilityNodeInfoCompat}, to follow fixes made in Android
4.1 (API level 16).</li>
<li>Added support for accessibility scroll actions in {@link
android.support.v4.view.ViewPager}.</li>
</ul>
</li>
<li>General improvements
<ul>
<li>Updated {@link android.support.v4.app.TaskStackBuilder} to reflect API changes in
Android 4.1 (API level 16).</li>
<li>Enhanced {@link android.support.v4.app.TaskStackBuilder} to allow it to be used
from a Service.</li>
<li>Added support for {@link android.support.v4.content.IntentCompat EXTRA_HTML_TEXT}
to {@link android.support.v4.app.ShareCompat}.</li>
<li>Updated {@link android.support.v4.app.NotificationCompat.Builder} to support the
{@link android.support.v4.app.NotificationCompat.Builder#setNumber setNumber()} method.</li>
<li>Added support in {@link android.support.v4.net.ConnectivityManagerCompat} for the
{@link android.support.v4.net.ConnectivityManagerCompat#isActiveNetworkMetered
isActiveNetworkMetered()} method.</li>
</ul>
</li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="toggle-content closed">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""
/>Support Package, revision 8</a> <em>(April 2012)</em>
</p>
<div class="toggle-content-toggleme">
<dl>
<dt>Changes for v4 support library:</dt>
<dd>
<ul>
<li>Fixed intent flags for {@link android.app.PendingIntent} objects generated
by {@link android.support.v4.app.TaskStackBuilder}.</li>
<li>Removed unused attributes from the gridlayout library projects to make sure
the library can be built with API level 7 and higher.</li>
<li>Added {@code .classpath} and {@code .project} files for the gridlayout
library project.</li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="toggle-content closed">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""
/>Support Package, revision 7</a> <em>(March 2012)</em>
</p>
<div class="toggle-content-toggleme">
<dl>
<dt>Changes for v4 support library:</dt>
<dd>
<ul>
<li>Added {@link android.support.v4.app.ShareCompat}, which provides helper classes
for sending and receiving content for social sharing applications, including new metadata for
attributing shared data to the source app. This class also provides compatible integration with the
new {@link android.widget.ShareActionProvider} in Android 4.0.</li>
<li>Added {@link android.support.v4.app.NavUtils} and {@link
android.support.v4.app.TaskStackBuilder} to provide support for implementing the
<a href="{@docRoot}design/index.html">Android Design</a> guidelines for navigation. These
additions include a way to implement the action bar's <em>Up</em> button across versions.
For an example implementation of this pattern, see the AppNavigation sample in
({@code <em><sdk></em>/samples/<em><platform></em>/AppNavigation}).</li>
<li>Added {@link android.support.v4.app.NotificationCompat.Builder} to provide a
compatibility implementation of Android 3.0's {@link android.app.Notification.Builder} helper class
for creating standardized system notifications.</li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="toggle-content closed">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""
/>Support Package, revision 6</a> <em>(December 2011)</em>
</p>
<div class="toggle-content-toggleme">
<p class="note"><strong>Note:</strong> Reference for support library APIs are now available with
the framework references, for example: {@link android.support.v4.app}.</p>
<dl>
<dt>Changes for v4 support library:</dt>
<dd>
<ul>
<li>Changes to ViewPager:
<ul>
<li>Added extra decorative view support for {@link android.support.v4.view.ViewPager}.
Decorative views may be supplied as child views of a pager in XML layout.</li>
<li>Added {@link android.support.v4.view.PagerAdapter#getPageTitle
PagerAdapter.getPageTitle()} to supply title strings for pages, which defaults to no
title for each page.</li>
<li>Added {@link android.support.v4.view.PagerTitleStrip}, a non-interactive title
strip, that can be added as a child of ViewPager. Developers can supply text
appearance and color, as well as layout sizing and gravity information.</li>
<li>Updated {@link android.support.v4.view.PagerAdapter} methods to take ViewGroup
objects, rather than View to avoid class casting in adapter implementations.</li>
<li>Updated {@link android.support.v4.view.ViewPager} to use Launcher-style
fling behavior.</li>
<li>Bug fixes for user interface interaction and test automation.</li>
</ul>
</li>
<li>Support for Fragments:
<ul>
<li>Changed {@code setStartDeferred()} method to {@link
android.support.v4.app.Fragment#setUserVisibleHint}.</li>
<li>Added deferred start for off-screen pages to improve performance.</li>
</ul>
</li>
<li>Support for Accessiblity APIs:
<ul>
<li>Updated {@link android.support.v4.view.AccessibilityDelegateCompat} methods
to return empty lists instead of null.</li>
<li>Added new APIs needed by the v4 samples.</li>
</ul>
</li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="toggle-content closed">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""
/>Support Package, revision 5</a> <em>(December 2011)</em>
</p>
<div class="toggle-content-toggleme">
<dl>
<dt>Changes for v4 support library:</dt>
<dd>
<ul>
<li>Support for Accessiblity APIs:
<ul>
<li>Added {@link android.support.v4.view.AccessibilityDelegateCompat}
to support {@link android.view.View.AccessibilityDelegate}.</li>
<li>Added {@link android.support.v4.view.accessibility.AccessibilityEventCompat}
to support {@link android.view.accessibility.AccessibilityEvent}.</li>
<li>Added {@link android.support.v4.view.accessibility.AccessibilityManagerCompat}
to support {@link android.view.accessibility.AccessibilityManager}.</li>
<li>Added {@link android.support.v4.view.accessibility.AccessibilityNodeInfoCompat}
to support {@link android.view.accessibility.AccessibilityNodeInfo}.</li>
<li>Added {@link android.support.v4.view.accessibility.AccessibilityRecordCompat}
to support {@link android.view.accessibility.AccessibilityRecord}.</li>
<li>Added {@link
android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat}
to support {@link android.accessibilityservice.AccessibilityServiceInfo}.</li>
<li>Added {@link android.support.v4.view.ViewGroupCompat}
to support accessibility features in {@link android.view.ViewGroup}.
</li>
<li>Modified {@link android.support.v4.view.ViewCompat}
to support accessibility features in {@link android.view.View}.</li>
</ul>
</li>
<li>Changes to ViewPager:
<ul>
<li>Added support for margins between pages.
An optional {@link android.graphics.drawable.Drawable} can be provided
to fill the margins.</li>
<li>Added support for {@link android.widget.EdgeEffect}.</li>
<li>Added support for keyboard navigation</li>
<li>Added support to control how many pages are kept to either side
of the current page.</li>
<li>Improved touch physics.</li>
<li>Bug fixes for user interface behavior.</li>
</ul>
</li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="toggle-content closed">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""
/>Support Package, revision 4</a> <em>(October 2011)</em>
</p>
<div class="toggle-content-toggleme">
<dl>
<dt>Changes for v4 support library:</dt>
<dd>
<ul>
<li>Added <code>EdgeEffectCompat</code> to
support {@link android.widget.EdgeEffect}.</li>
<li>Added <code>LocalBroadcastManager</code> to allow applications to easily
register for and receive intents within a single application without
broadcasting them globally.</li>
<li>Added support in <code>ViewCompat</code> to check for and set overscroll
modes for {@link android.view.View}s on Android 2.3 and later.</li>
<li>Changes to Fragment APIs:
<ul>
<li>Added new APIs to control the visibility of new menus.</li>
<li>Added custom animation APIs.</li>
<li>Added APIs in <code>FragmentActivity</code> to retain custom,
non-configuration instance data.</li>
<li>Various bug fixes.</li>
</ul>
</li>
<li>Fixed a {@link android.content.Loader} bug that caused issues in
canceling {@link android.os.AsyncTask}s when running on Froyo and older
versions of the platform. The support
code now uses its own version of {@link android.os.AsyncTask} to keep the same
behavior on all platform versions.</li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="toggle-content closed">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""
/>Compatibility Package, revision 3</a> <em>(July 2011)</em>
</p>
<div class="toggle-content-toggleme">
<dl>
<dt>Changes for v4 support library:</dt>
<dd>
<ul>
<li>Adds support for {@link android.app.Fragment.SavedState}</li>
<li>Adds {@code MotionEventCompat} to support newer {@link
android.view.MotionEvent} APIs</li>
<li>Adds {@code VelocityTrackerCompat} to support a newer {@link
android.view.VelocityTracker} APIs</li>
<li>Adds {@code ViewConfigurationCompat} to support a newer {@link
android.view.ViewConfiguration} APIs</li>
<li>All new APIs (available only in the support library) that allow you to create UIs
with horizontal paging, allowing users to swipe left and right between content views. Classes to
support this include:
<ul>
<li>{@code ViewPager}: A {@link android.view.ViewGroup} that manages the
layout for the child views, which the user can swipe between.</li>
<li>{@code PagerAdapter}: An adapter that populates the {@code ViewPager} with the
views that represent each page.</li>
<li>{@code FragmentPagerAdapter}: An extension of {@code PagerAdapter} for flipping
between fragments.</li>
<li>{@code FragmentStatePagerAdapter}: An extension of {@code PagerAdapter} for
flipping between fragments that uses the library's support for {@link
android.app.Fragment.SavedState}.</li>
</ul>
</li>
</ul>
</dd>
<dt>New v13 support library:</dt>
<dd>
<ul>
<li>Includes the {@code FragmentPagerAdapter} and {@code FragmentStatePagerAdapter}
to support the horizontal paging.
<p>These are exactly the same as the APIs added to the v4 support library, but rely on
other platform components in Android 3.2. Use this library instead of v4 if you're developing for
Android 3.2 and higher (all other APIs in the v4 library are already available with API level
13).</p>
</li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="toggle-content closed">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""
/>Compatibility Package, revision 2</a> <em>(May 2011)</em>
</p>
<div class="toggle-content-toggleme">
<dl>
<dt>Changes for v4 library:</dt>
<dd>
<ul>
<li>Support for fragment animations</li>
<li>Fix {@code android.support.v4.app.Fragment#onActivityResult Fragment.onActivityResult()}
bug</li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="toggle-content closed">
<p><a href="#" onclick="return toggleContent(this)">
<img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-content-img" alt=""
/>Compatibility Package, revision 1</a> <em>(March 2011)</em>
</p>
<div class="toggle-content-toggleme">
<p>Initial release with the v4 library.</p>
</div>
</div>
<h2 id="Downloading">Downloading the Support Package</h2>
<p>The Support Package is provided as a downloadable package from the Android SDK
Manager. To install:</p>
<ol>
<li>Launch the Android SDK Manager.
<p>From Eclipse, you can select <strong>Window</strong>
> <strong>Android SDK Manager</strong>. Or, launch {@code SDK Manager.exe} from
the {@code <sdk>/} directory (on Windows only) or {@code android} from the {@code
<sdk>/tools/} directory.</p></li>
<li>Expand the Android Repository, check <strong>Android Support package</strong>
and click <strong>Install selected</strong>.</li>
<li>Proceed to install the package.</li>
</ol>
<p>When done, all files (including source code, samples, and the JAR files) are saved
into the <code><sdk>/extras/android/support/</code> directory. This directory contains
each of the different support libraries, such as the library for API level 4 and up and the library
for API level 13 and up, each named with the respective version (such as {@code v4/}).</p>
<h2 id="SettingUp">Setting Up a Project to Use a Library</h2>
<p>To add one of the libraries to your Android project:</p>
<dl>
<dt>
Add the JAR file to your project.
</dt>
<dd>
Copy the JAR file for the library you want to use into your Android project. To do this:
<ul>
<li>
Create the directory {@code libs/} at the root of your project
(next to {@code src/}, {@code res/}, and so forth).
</li>
<li>
Locate the JAR file for the library you want to use and copy it into the
{@code libs/} directory.
<p>
For example, the library that supports API level 4 and up is located at
{@code <sdk>/extras/android/support/v4/android-support-v4.jar}.
</p>
</li>
</ul>
<p>
Your build system may expect to find the JAR file in a directory other than
{@code libs}. Read the documentation for your build system to learn where to put the
JAR file.
</p>
</dd>
<dt>
If necessary, add the {@code libs/} directory to your build path.
</dt>
<dd>
Read the documentation for your build system to learn how to add the JAR file to the
build path.
</dd>
</dl>
<p>
To confirm that you've added the JAR file to the correct directory and added it to the build
path:
</p>
<ol>
<li>
Edit one of your source files to add an {@code import} statement that imports a
class from the {@code android.support.*} package.
</li>
<li>
Build your app. The code should compile cleanly.
</li>
<li>
As a double-check, run your app. It should run correctly, without any runtime exceptions
indicating that the class in {@code android.support.*} can't be found.
</li>
</ol>
<p>Your application is now ready to use the library APIs. All the
provided APIs are available in the {@code android.support} package (for
example, {@code android.support.v4}).</p>
<p class="note"><strong>Tip:</strong> To see the library APIs in action, take a look at the sample
apps in {@code <sdk>/extras/android/support/<version>/samples/}.</p>
<p class="warning"><strong>Warning:</strong> Be certain that you not confuse the standard
{@code android} packages with those in {@code android.support} library. Some code completion tools
might
get this wrong, especially if you're building against recent versions of the platform. To be safe,
keep your build target set to the same version as you have defined for your <a
href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code android:minSdkVersion}</a>
and double check the import statements for classes that also exist in the support library, such as
{@code SimpleCursorAdapter}.</p>
<h2 id="Using">Using the v4 Library APIs</h2>
<p>The support library for v4 provides access to several classes introduced with Android 3.0 and
beyond, plus some updated version of existing classes, and even some APIs that currently don't
exist in the Android platform. Some of the most useful and notable classes that have
counterparts in the v4 support library are:</p>
<ul>
<li>{@link android.app.Fragment}</li>
<li>{@link android.app.FragmentManager}</li>
<li>{@link android.app.FragmentTransaction}</li>
<li>{@link android.app.ListFragment}</li>
<li>{@link android.app.DialogFragment}</li>
<li>{@link android.app.LoaderManager}</li>
<li>{@link android.content.Loader}</li>
<li>{@link android.content.AsyncTaskLoader}</li>
<li>{@link android.content.CursorLoader}</li>
</ul>
<p>For each of the classes above (and others not listed), the APIs work almost exactly the same
as the counterparts in the latest Android platform. Thus, you can usually refer to
the online documentation for information about the supported APIs. There are some
differences, however. Most notably:</p>
<ul>
<li>When creating an activity to use fragments, you must declare your activity to extend the
{@link android.support.v4.app.FragmentActivity} class (instead of the traditional
{@link android.app.Activity} class).</li>
<li>To manage your fragments and loaders, you must use the methods
{@link android.support.v4.app.FragmentActivity#getSupportFragmentManager
FragmentActivity.getSupportFragmentManager()} and
{@link android.support.v4.app.FragmentActivity#getSupportLoaderManager
FragmentActivity.getSupportLoaderManager()} (instead of the
{@link android.app.Activity#getFragmentManager()} and
{@link android.app.Activity#getLoaderManager()} methods).</li>
<li>The {@link android.app.ActionBar} is <strong>not supported</strong> by the library.
However, when creating your <a href="{@docRoot}guide/topics/ui/menus.html#options-menu">Options
Menu</a>, you can declare which items should be added to the Action Bar when it's available (on
Android 3.0 or later). You can do so with the
{@link android.support.v4.view.MenuCompat#setShowAsAction MenuCompat.setShowAsAction()} method, for
example:
<pre>
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options, menu);
MenuCompat.setShowAsAction(menu.findItem(R.id.action_search), 1);
return true;
}
</pre>
<p>Also see the <a href="{@docRoot}resources/samples/ActionBarCompat/index.html">Action Bar
Compatibility</a> sample for a demonstration of how to use {@link android.app.ActionBar} on Android
3.0+ and also support action bar functionality on older versions.</p>
</li>
</ul>
<div class="note"><p><strong>Tip:</strong> To enable the Holographic theme on devices
running Android 3.0 or higher, declare in your manifest file that your application targets
API level 11, for example:</p>
<pre>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11" />
</pre>
<p>This way, your application automatically receives the Holographic theme and the Action Bar for
each activity when running on Android 3.0 and higher.</p>
</div>
<p>For more information about how you can optimize your application for the latest
Android-powered devices, read <a href="{@docRoot}guide/practices/optimizing-for-3.0.html">Optimizing
Apps for Android 3.0</a>.</p>
<h2 id="Docs">Reference Docs</h2>
<p>The reference documentation for the Support Packages is included as part of the Android
online developer documentation:</p>
<ul>
<li><a href="{@docRoot}reference/android/support/v4/app/package-summary.html">Support Package
API 4 Reference</a></li>
<li><a href="{@docRoot}reference/android/support/v13/app/package-summary.html">Support Package
API 13 Reference</a></li>
</ul>
<h2 id="Samples">Samples</h2>
<p>If you want to see some code that uses the support libraries, samples are included with the
Support Package, inside each support library directory, for example; {@code
<sdk>/extras/android/support/v4/samples/}. You can also view these samples as part of the
Android online developer documentation:</p>
<ul>
<li><a href="{@docRoot}resources/samples/Support4Demos/index.html">Support API 4 Demos</a></li>
<li><a href="{@docRoot}resources/samples/Support13Demos/index.html">Support API 13 Demos</a></li>
</ul>
<p>Additionally, the <a href="http://code.google.com/p/iosched/">Google I/O App</a> is a complete
application that uses the v4 support library to provide a single APK for both handsets and tablets
and also demonstrates some of Android's best practices in Android UI design.</p>
|