Support Library Samples in The Android SDK

How to Load and Run the Android Support Library Demos

This tutorial will show you how to load the samples provided with the Android SDK that demonstrate using the Android Support Library, some refer to it as Android Support Package or the Android Compatibility Package. The online Android developer documentation does not give enough detail on getting the Support Library demos running, this article covers that shortfall.

What is the Android Support Library?

The Android Operating System (OS) is updated regularly to add new features, support new devices and implement new ideas. This requires changes and additions to the Application Programming Interface (API). For Applications (Apps) to be widely used they need to run on devices with earlier APIs as well as devices that have the new features. To help developers achieve this Google provides a Support Library that allows some of the newer API features to be used on earlier devices.

For example when Android version 3.0 (Honeycomb, API 3.0) was released, to support tablet style devices, it provided the new Fragment class. The use of Fragments allows a User Interface (UI) to be divided into smaller sections allowing for improved App design when dealing with larger screens. A tablet App may have a screen composed of three Fragments, when that App is run on a device with a small screen the three Fragments may represent three separate screens. To run an App based on Fragments on a device with a version of Android lower that 3.0, i.e. API 10 or earlier, the Android Support Library is required. It has implementations of some of the new Android APIs to allow earlier devices to run code written for the new APIs, helping with an Apps backwards compatibility. (Note that this differs from Android Compatibility Mode which is what new devices use to run old Apps.)

Android Support Library Installation

Android Support Library InstallThe Android Support Library and compatibility samples are installed via the SDK Manager. If a full install of the Android SDK was done then in the Android SDK folder the compatibility files are in android-sdk/extras/android/compatibility. If the Android Support Library is not installed simply run SDK Manager (SDK Manager.exe on Windows). Open the Extras folder. Select Android Support Library then click the Install 1 package button (accepting the licence agreement).

The Android SDK has available two versions of the Support LIbrary:

  • android-support-v4.jar – Version 4 is for Apps aimed at Android Version 1.6 (Donut, API 4) and later.
  • android-support-v13.jar – Version 13 is for Apps aimed at Android 3.2 ( API 13) and later.

The recent Android Development Tools (ADT) Eclipse plug-in automatically adds the Version 4 Support Library when a new project is started. To change to the later library when targeting only newer devices use the Java Build Path option from the projects Properties (select the project in the Eclipse Package Explorer and use the File menu to bring up Properties). Use the Libraries tab to remove and add JARs.

The release of Ice Cream Sandwich (Android 4.0, API 14) made available a new layout, the GridLayout is designed to help with precision when designing screens. There has been a  GridView since the first Android release, which is useful to display a grid of repeating data in repeating Views of the same type. A GridLayout can contain assorted Views in its cells to support complex layouts with more precision and more efficiency than nesting many LinearLayouts.

To aid backwards compatibility the GridLayout is available in a JAR file for devices running Android 2.1 (API 7) and later. The android-support-v7-gridlayout.jar is in the folder android-sdk/extras/android/compatibility/v7/gridlayout/libs under the Android SDKs install location.

Load the Support Library Samples Into an Eclipse Project

There are three samples in the android-sdk/extras/android/compatibility/samples folder:

  • Support4Demos – Accessibility Delegate and Manager, Content (Local Service Broadcaster), Fragment (Alert Dialog, Arguments, Context Menu, Custom Animation, Dialog, Dialog or Activity, Hide and Show, Layout, List Array, Menu, Nesting Tabs, Pager, Receive Result, Retain Instance, Stack, State Pager, Tabs, Tabs and Pager), Loader (Cursor, Custom, Retained, Throttle), Share Compatibility
  • Support13Demos – Fragment (Action Bar Tabs Pager, Nesting Pager, Nesting State Pager, Pager, State Pager)
  • SupportAppNavigation – Simple Up Navigation, Peer Activities, View from other task, Content Category, Notifications (direct and interstitial)

There is no sample for using the GridLayout compatibility JAR but in the android-sdk/extras/android/compatibility/v7/gridlayout folder there is a read me and values XML files to instruct on using the support GridLayout JAR.

To load a Support Library example demo App an empty project is created in Eclipse and the source code is imported from the samples directory.

Load and Run the Android Support Library v4 Demo

Start a new project and in the first dialog enter values as for this screen:

Support Library v4 Samples

Click Next and uncheck the options Create custom launcher icon and Create activity, then click Finish. The empty Support4Demos project is created in the workspace. With the project highlighted use the File menu and select Import. In the Import dialog expand the General folder and select File System and then click Next. Use the Browse button to select the android-sdk/extras/android/compatibility/samples/Support4Demos folder under the Android SDK install location. Expand the Support4Demos folder and check the res and src folders, also check the AndroidManifest.xml file.

Import the Support Library v4 Sample

Click Finish and then run the demo.

Android Support Library v4 Demo

Load and Run the Android Support Library v13 Demo

Start a new project and in the first dialog enter values as for this screen:

Continue as for loading the v4 demo as above (obviously using the Support13Demos folder).  From the projects Properties (select the project in the Eclipse Package Explorer and use the File menu to bring up Properties). Use the Java Build Path option, under the Libraries tab, to remove the android-support-v4.jar library and add the android-support-v13.jar via the Add External JARs button. Use the Order and Export tab and check android-support-v13.jar so that it’s code is included in the built Android Package (APK) install file. Run the demo.

Load and Run the Support Library App Navigation Demo

Start a new project and in the first dialog enter values as for this screen:

Android Support Library Navigation Sample

Continue as for loading the v4 demo as above (using the SupportAppNavigation folder). Run the demo.

Android Support Library Navigation Demo

Additional Information

See also the Support Library online developer pages: http://developer.android.com/tools/extras/support-library.html. Look for the Support Package API 4 and API 13 Reference links for detailed information on what APIs the Library implements.

2 thoughts on “Support Library Samples in The Android SDK

Leave a Reply

Your email address will not be published. Required fields are marked *

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.