Using Code Templates. Docand Developer tools
Advertisement
Advertisement
Using Code Templates
23. Using Code Templates
Content from developer.android.com/tools/projects/templates.html through their Creative Commons Attribution 2.5 license
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:
In this section
• Application Templates
• BlankActivity Template
• Full Screen Activity Template
• Master Detail Flow Template
• Activity Templates
• Login Activity Template
• Settings Activity Template
• Other Templates
• Application Templates
• Activity Templates
• Other Templates
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.
• BlankActivity
• FullScreenActivity
• MasterDetailFlow
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
137
Content from developer.android.com/tools/projects/templates.html through their Creative Commons Attribution 2.5 license
Using Code Templates
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 (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 Fragment class and a tabbed user interface.
This template includes:
• ActionBar for tab controls
• Fragment objects for section content
• Optional swipe gesture support based on the swipe view design pattern, which extends FragmentPagerAdapter to manage section fragments
138
Content from developer.android.com/tools/projects/templates.html through their Creative Commons Attribution 2.5 license
Using Code Templates
The BlankActivity template with the Navigation Type: Swipe
Views + Title Strip option creates an application with three
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:
• PagerTitleStrip for section titles
• Fragment objects for section content
• FragmentPagerAdapter to manage section fragments
The BlankActivity template with the Navigation Type:
Dropdown option creates an application that extends
FragmentActivity, containing three Fragment sections, with an ActionBar using list mode navigation.
This template includes:
• ActionBar for list mode navigation
• Fragment objects for section content
Full Screen Activity Template
Example Description
139
Content from developer.android.com/tools/projects/templates.html through their Creative Commons Attribution 2.5 license
Download
Advertisement