From 025ec882be3de274ddc935c7d669c4e86a74e0eb Mon Sep 17 00:00:00 2001
From: Joe Fernandez Eclipse and the ADT plugin provide GUIs and wizards to create all three types of projects
(Android project, Library project, and Test project):
-
+
The ADT plugin provides a New Project Wizard that you can use to quickly create a new Android
- project (or a project from existing code). To create a new project: The ADT plugin provides a New Project Wizard that you can use to quickly create a new
+ Android project (or a project from existing code). To create a new project: Select the lowest platform with which your application is compatible. Note: You can change your the Build Target for your
+ Note: You can change the target SDK for your
project at any time: Right-click the project in the Package Explorer, select
Properties, select Android and then check the desired
- Project Target.
Creating an Android Project
-
-
minSdkVersion attribute in the
+ <uses-sdk>
+ element of your manifest file.
minSdkVersion attribute in the <uses-sdk> of your
- Android Manifest file. If you're unsure of the appropriate API Level to use, copy the API Level
- listed for the Build Target you selected in the Target tab.Tip: You can also start the New Project Wizard from the - New icon in the toolbar.
+Tip: You can also start the New Project Wizard by clicking the
+ New
icon in the toolbar.
A library project is a standard Android project, so you can create a new one in the same way as you would a new application project.
-When you are creating the library project, you can select any application name, package, and - set other fields as needed, as shown in figure 1.
+To create a new library project:
+ +Next, set the project's properties to indicate that it is a library project:
+You can also convert an existing application project into a library. To do so, simply open the + Properties for the project and select the is Library checkbox, as shown in + the figure below.
+ +
+ Figure 1. Marking a project as an Android library.
+ +To set the a project's properties to indicate that it is a library project:
The new project is now marked as a library project. You can begin moving source code and - resources into it, as described in the sections below.
+Once you create a library project or mark an existing project as a library, you can reference + the library project in other Android application projects. For more information, see the + Referencing a library project section. -
You can also convert an existing application project into a library. To do so, simply open the - Properties for the project and select the "is Library" checkbox. Other application projects can - now reference the existing project as a library project.
- -
-
- Figure 1. Marking a project as an - Android library project.
For example, the TicTacToeLib example library
- project declares the Activity GameActivity:
GameActivity:
<manifest> ... @@ -167,6 +200,9 @@ parent.link=index.htmlTo add a reference to a library project, follow these steps:
+
- Make sure that both the project library and the application project that depends on it are + in your workspace. If one of the projects is missing, import it into your workspace.
+- In the Package Explorer, right-click the dependent project and select Properties.
@@ -214,7 +250,7 @@ parent.link=index.htmlFor example, the TicTacToeMain example - application declares the library Activity
+ application declares the library activityGameActivitylike this:GameActivitylike this:<manifest> ... diff --git a/docs/html/tools/projects/templates.jd b/docs/html/tools/projects/templates.jd new file mode 100644 index 0000000..fce24fd --- /dev/null +++ b/docs/html/tools/projects/templates.jd @@ -0,0 +1,347 @@ +page.title=Using Code Templates +@jd:body + ++ + +++ + +++In this document
+ + + +The SDK tools provide templates for quickly creating Android application projects with the basic + structure or for adding components to your existing projects. The code templates + provided by the Android SDK follow the Android design and development guidelines to get you on the + right track to creating a beautiful, functional application.
+ +There are several types of Android code templates, which can create anything from an entire + application down to specific application components. The main categories of code templates are as + follows:
+ +Application Templates
+ +Application templates create basic Android applications that you can immediately run and test + on your Android device. These templates are available when you create a new Android project, + though you can also use these templates to add new activities + to an existing project.
+ +To use Android application templates:
+ ++
+ +- In Eclipse, with the Android Development Tools (ADT) plugin installed, select File + > New > Android.
+- Select Android > Android Application Project, and click + Next.
+- Enter the settings for your application, including Application Name, + Project Name, Package Name, API level settings and + presentation Theme, and click Next.
+- Enter the project configuration options, and click Next.
+- Optionally enter launcher icon settings, and click Next.
+- In the Create Activity page, select an application template to use. + +
++ Note: The other activity template options also create applications, however these + applications require further modification before they can be launched on an Android device. +
+ + +Blank Activity Template
+ ++
+ + ++ + +Example + +Description ++ + ++ + +
+ The BlankActivity template with the Navigation Type: + None option creates a simple application that follows the + Android Design guidelines. Use this template to + create a basic, minimal app as a starting point for your project.
+ +This template includes:
+ ++
+- Title bar ({@link android.app.ActionBar} on Android 3.0 and later)
+- Options menu (action overflow on Android 3.0 and later)
+- Basic layout
++ + ++ + +
+ The BlankActivity template with the Navigation Type: + Tabs or Tabs + Swipe option creates an application with + three sections based on the {@link android.app.Fragment} class and a tabbed user + interface.
+ +This template includes:
+ ++
+- {@link android.app.ActionBar} for tab controls
+- {@link android.app.Fragment} objects for section content
+- Optional swipe gesture support based on the + swipe view design pattern, + which extends {@link android.support.v4.app.FragmentPagerAdapter} to manage section + fragments
++ + ++ + +
+ The BlankActivity template with the Navigation Type: + Swipe Views + Title Strip option creates an application with three + {@link android.app.Fragment} sections, a compact title strip header (known as + Scrollable Tabs in the + Android Design guide) and swipe navigation between + the sections, based on the swipe + view design pattern.
+ +This template includes:
+ ++
+- {@link android.support.v4.view.PagerTitleStrip} for section titles
+- {@link android.app.Fragment} objects for section content
+- {@link android.support.v4.app.FragmentPagerAdapter} to manage section fragments
++ ++ + +
+ The BlankActivity template with the Navigation Type: + Dropdown option creates an application that extends + {@link android.support.v4.app.FragmentActivity}, containing three + {@link android.app.Fragment} sections, with an {@link android.app.ActionBar} using list mode + navigation.
+ +This template includes:
+ ++
+- {@link android.app.ActionBar} for list mode navigation
+- {@link android.app.Fragment} objects for section content
+Full Screen Activity Template
+ ++
+ + ++ + +Example + +Description ++ ++ + +
+ This template provides an implementation of an activity which alternates between a + primary, full screen view and a view with standard user interface controls, including the + notification bar and application title bar. The full screen view is the default and a user + can activate the standard view by touching the device screen.
+ +This template includes:
+ ++
+- {@code SystemUiHider} implementation that manages hiding of the system user interface + using a version-compatible approach
+- Basic layout
+Master Detail Flow Template
+ ++
+ + ++ + +Example + +Description ++ ++ + +
+ This template creates an adaptive layout for a set of items and associated details. On a + tablet device, the item list and item details are displayed on the same screen. On a smaller + device, the list and details are displayed on separate screens.
+ ++ Note: This template follows the recommendations of the + Designing for Multiple Screens + Android training. +
+ +This template includes:
+ ++
- Adaptive layout using + alternative resource XML files
+- {@link android.support.v4.app.FragmentActivity}, {@link android.app.Fragment} and + {@link android.support.v4.app.ListFragment} implementations
+Activity Templates
+ +Android activity templates provide options to add new activities to your existing + application.
+ +To use Android activity templates:
+ ++
+ +- Right click the project folder of the Android application where you want to add an + activity.
+- Select New > Other...
+- Select Android > Android Activity, and click Next.
+- Select an activity template, then follow the instructions to add it to your existing + application. + +
+These templates create the same type of activity as they do when used as an application template, +however the following templates create activities which are specifically intended to be used as part +of an existing application.
+ + +Login Activity Template
+ ++
+ + ++ + +Example + +Description ++ ++ + +
+ This activity template provides input fields and a sample implementation of + an {@link android.os.AsyncTask} that asks users to login or register with their credentials.
+ +This template includes:
+ ++
+- Recommended user interface for requesting login information
+- {@link android.os.AsyncTask} implementation for handing network operations separately + from the main user interface thread
+- Progress indicator during network operations
+Settings Activity Template
+ ++
+ + ++ + +Example + +Description ++ ++ + +
+ This template extends the {@link android.preference.PreferenceActivity} class and uses an + XML file to create preference settings. This template also demonstrates how to implement + several data types for settings.
+ +This template includes:
+ ++
+- Activity extending {@link android.preference.PreferenceActivity}
+- Preference values defined using XML files added to the {@code res/xml/} directory of + your project.
+Other Templates
+ +Android object templates provide options to add new components to your existing application, +including the previously mentioned activities as well as the following additional items:
+ +To use Android object templates:
+ ++
-- cgit v1.1- Right click the project folder of the Android application where you want to add a code + component.
+- Select New > Other...
+- Select Android > Android Object, and click Next.
+- Select an object template, then follow the instructions to add it to your existing + application. +
++
+- {@link android.content.BroadcastReceiver}
+- {@link android.content.ContentProvider}
+- Custom View
+- {@link android.app.Service}
+