1 page.title=Using Code Templates 2 @jd:body 3 4 <div id="qv-wrapper"> 5 <div id="qv"> 6 <h2>In this document</h2> 7 8 <ol> 9 <li><a href="#app-templates">Application Templates</a> 10 <ol> 11 <li><a href="#blank-activity">BlankActivity Template</a></li> 12 <li><a href="#full-screen-activity">Full Screen Activity Template</a></li> 13 <li><a href="#master-detail-activity">Master Detail Flow Template</a></li> 14 </ol> 15 </li> 16 17 <li><a href="#activity-templates">Activity Templates</a> 18 <ol> 19 <li><a href="#login-activity">Login Activity Template</a></li> 20 <li><a href="#settings-activity">Settings Activity Template</a></li> 21 </ol> 22 </li> 23 <li><a href="#object-templates">Other Templates</a></li> 24 </ol> 25 26 </div> 27 </div> 28 29 30 <p>The SDK tools provide templates for quickly creating Android application projects with the basic 31 structure or for adding components to your existing projects. The code templates 32 provided by the Android SDK follow the Android design and development guidelines to get you on the 33 right track to creating a beautiful, functional application.</p> 34 35 <p>There are several types of Android code templates, which can create anything from an entire 36 application down to specific application components. The main categories of code templates are as 37 follows:</p> 38 39 <ul> 40 <li><a href="#app-templates">Application Templates</a></li> 41 <li><a href="#activity-templates">Activity Templates</a></li> 42 <li><a href="#object-templates">Other Templates</a></li> 43 </ul> 44 45 46 <h2 id="app-templates">Application Templates</h2> 47 48 <p>Application templates create basic Android applications that you can immediately run and test 49 on your Android device. These templates are available when you create a new Android project, 50 though you can also use these templates to <a href="#activity-templates">add new activities</a> 51 to an existing project.</p> 52 53 <p>To use Android application templates:</p> 54 55 <ol> 56 <li>In Eclipse, with the Android Development Tools (ADT) plugin installed, select <strong>File 57 > New > Android</strong>.</li> 58 <li>Select <strong>Android > Android Application Project</strong>, and click 59 <strong>Next</strong>.</li> 60 <li>Enter the settings for your application, including <strong>Application Name</strong>, 61 <strong>Project Name</strong>, <strong>Package Name</strong>, API level settings and 62 presentation <strong>Theme</strong>, and click <strong>Next</strong>.</li> 63 <li>Enter the project configuration options, and click <strong>Next</strong>.</li> 64 <li>Optionally enter launcher icon settings, and click <strong>Next</strong>.</li> 65 <li>In the <strong>Create Activity</strong> page, select an application template to use. 66 <ul> 67 <li><a href="#blank-activity">BlankActivity</a></li> 68 <li><a href="#full-screen-activity">FullScreenActivity</a></li> 69 <li><a href="#master-detail-activity">MasterDetailFlow</a></li> 70 </ul> 71 </li> 72 </ol> 73 74 <p class="note"> 75 <strong>Note:</strong> The other activity template options also create applications, however these 76 applications require further modification before they can be launched on an Android device. 77 </p> 78 79 80 <h3 id="blank-activity">Blank Activity Template</h3> 81 82 <table> 83 <tr> 84 <th width="206px">Example</th> 85 86 <th>Description</th> 87 </tr> 88 89 <tr> 90 <td><img src="{@docRoot}images/code_templates/ba-no-navigation.png" alt="" /> 91 </td> 92 93 <td><p>The <strong>BlankActivity</strong> template with the <strong>Navigation Type: 94 None</strong> option creates a simple application that follows the 95 <a href="{@docRoot}design/index.html">Android Design</a> guidelines. Use this template to 96 create a basic, minimal app as a starting point for your project.</p> 97 98 <p>This template includes:</p> 99 100 <ul> 101 <li>Title bar ({@link android.app.ActionBar} on Android 3.0 and later)</li> 102 <li>Options menu (action overflow on Android 3.0 and later) </li> 103 <li>Basic layout</li> 104 </ul> 105 </td> 106 </tr> 107 108 <tr> 109 <td><img src="{@docRoot}images/code_templates/ba-tabs.png" alt="" /> 110 </td> 111 112 <td><p>The <strong>BlankActivity</strong> template with the <strong>Navigation Type: 113 Tabs</strong> or <strong>Tabs + Swipe</strong> option creates an application with 114 three sections based on the {@link android.app.Fragment} class and a tabbed user 115 interface.</p> 116 117 <p>This template includes:</p> 118 119 <ul> 120 <li>{@link android.app.ActionBar} for tab controls</li> 121 <li>{@link android.app.Fragment} objects for section content</li> 122 <li>Optional swipe gesture support based on the 123 <a href="{@docRoot}design/patterns/swipe-views.html">swipe view</a> design pattern, 124 which extends {@link android.support.v4.app.FragmentPagerAdapter} to manage section 125 fragments</li> 126 </ul> 127 </td> 128 </tr> 129 130 <tr> 131 <td><img src="{@docRoot}images/code_templates/ba-title-strip.png" alt="" /> 132 </td> 133 134 <td><p>The <strong>BlankActivity</strong> template with the <strong>Navigation Type: 135 Swipe Views + Title Strip</strong> option creates an application with three 136 {@link android.app.Fragment} sections, a compact title strip header (known as 137 <a href="{@docRoot}design/building-blocks/tabs.html#scrollable">Scrollable Tabs</a> in the 138 <a href="{@docRoot}design/index.html">Android Design</a> guide) and swipe navigation between 139 the sections, based on the <a href="{@docRoot}design/patterns/swipe-views.html">swipe 140 view</a> design pattern.</p> 141 142 <p>This template includes:</p> 143 144 <ul> 145 <li>{@link android.support.v4.view.PagerTitleStrip} for section titles</li> 146 <li>{@link android.app.Fragment} objects for section content</li> 147 <li>{@link android.support.v4.app.FragmentPagerAdapter} to manage section fragments</li> 148 </ul> 149 </td> 150 </tr> 151 152 <tr> 153 <td><img src="{@docRoot}images/code_templates/ba-dropdown.png" alt="" /> 154 </td> 155 156 <td><p>The <strong>BlankActivity</strong> template with the <strong>Navigation Type: 157 Dropdown</strong> option creates an application that extends 158 {@link android.support.v4.app.FragmentActivity}, containing three 159 {@link android.app.Fragment} sections, with an {@link android.app.ActionBar} using list mode 160 navigation.</p> 161 162 <p>This template includes:</p> 163 164 <ul> 165 <li>{@link android.app.ActionBar} for list mode navigation</li> 166 <li>{@link android.app.Fragment} objects for section content</li> 167 </ul> 168 </td> 169 </tr> 170 </table> 171 172 173 <h3 id="full-screen-activity">Full Screen Activity Template</h3> 174 175 <table> 176 <tr> 177 <th width="240px">Example</th> 178 179 <th>Description</th> 180 </tr> 181 182 <tr> 183 <td><img src="{@docRoot}images/code_templates/full-screen-activity.png" alt="" /> 184 </td> 185 186 <td><p>This template provides an implementation of an activity which alternates between a 187 primary, full screen view and a view with standard user interface controls, including the 188 notification bar and application title bar. The full screen view is the default and a user 189 can activate the standard view by touching the device screen.</p> 190 191 <p>This template includes:</p> 192 193 <ul> 194 <li>{@code SystemUiHider} implementation that manages hiding of the system user interface 195 using a version-compatible approach</li> 196 <li>Basic layout</li> 197 </ul> 198 </td> 199 </tr> 200 </table> 201 202 203 <h3 id="master-detail-activity">Master Detail Flow Template</h3> 204 205 <table> 206 <tr> 207 <th width="350px">Example</th> 208 209 <th>Description</th> 210 </tr> 211 212 <tr> 213 <td><img src="{@docRoot}images/code_templates/master-detail-flow.png" alt=""/> 214 </td> 215 216 <td><p>This template creates an adaptive layout for a set of items and associated details. On a 217 tablet device, the item list and item details are displayed on the same screen. On a smaller 218 device, the list and details are displayed on separate screens.</p> 219 220 <p class="note"> 221 <strong>Note:</strong> This template follows the recommendations of the 222 <a href="{@docRoot}training/multiscreen/index.html">Designing for Multiple Screens</a> 223 Android training. 224 </p> 225 226 <p>This template includes:</p> 227 228 <ul> 229 <li>Adaptive layout using 230 <a href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources" 231 >alternative resource</a> XML files</li> 232 <li>{@link android.support.v4.app.FragmentActivity}, {@link android.app.Fragment} and 233 {@link android.support.v4.app.ListFragment} implementations</li> 234 </ul></td> 235 </tr> 236 </table> 237 238 239 <h2 id="activity-templates">Activity Templates</h2> 240 241 <p>Android activity templates provide options to add new activities to your existing 242 application.</p> 243 244 <p>To use Android activity templates:</p> 245 246 <ol> 247 <li>Right click the project folder of the Android application where you want to add an 248 activity.</li> 249 <li>Select <strong>New > Other...</strong></li> 250 <li>Select <strong>Android > Android Activity</strong>, and click <strong>Next</strong>.</li> 251 <li>Select an activity template, then follow the instructions to add it to your existing 252 application. 253 <ul> 254 <li><a href="#login-activity">LoginActivity</a></li> 255 <li><a href="#settings-activity">SettingsActivity</a></li> 256 <li><a href="#blank-activity">BlankActivity</a></li> 257 <li><a href="#full-screen-activity">FullScreenActivity</a></li> 258 <li><a href="#master-detail-activity">MasterDetailFlow</a></li> 259 </ul> 260 </li> 261 </ol> 262 263 <p>These templates create the same type of activity as they do when used as an application template, 264 however the following templates create activities which are specifically intended to be used as part 265 of an existing application.</p> 266 267 268 <h3 id="login-activity">Login Activity Template</h3> 269 270 <table> 271 <tr> 272 <th width="206px">Example</th> 273 274 <th>Description</th> 275 </tr> 276 277 <tr> 278 <td><img src="{@docRoot}images/code_templates/login-activity.png" alt="" /> 279 </td> 280 281 <td><p>This activity template provides input fields and a sample implementation of 282 an {@link android.os.AsyncTask} that asks users to login or register with their credentials.</p> 283 284 <p>This template includes:</p> 285 286 <ul> 287 <li>Recommended user interface for requesting login information</li> 288 <li>{@link android.os.AsyncTask} implementation for handing network operations separately 289 from the main user interface thread</li> 290 <li>Progress indicator during network operations</li> 291 </ul> 292 </td> 293 </tr> 294 </table> 295 296 297 <h3 id="settings-activity">Settings Activity Template</h3> 298 299 <table> 300 <tr> 301 <th width="206px">Example</th> 302 303 <th>Description</th> 304 </tr> 305 306 <tr> 307 <td><img src="{@docRoot}images/code_templates/settings-activity.png" alt="" /> 308 </td> 309 310 <td><p>This template extends the {@link android.preference.PreferenceActivity} class and uses an 311 XML file to create preference settings. This template also demonstrates how to implement 312 several data types for settings.</p> 313 314 <p>This template includes:</p> 315 316 <ul> 317 <li>Activity extending {@link android.preference.PreferenceActivity}</li> 318 <li>Preference values defined using XML files added to the {@code res/xml/} directory of 319 your project.</li> 320 </ul> 321 </td> 322 </tr> 323 </table> 324 325 326 <h2 id="object-templates">Other Templates</h2> 327 328 <p>Android object templates provide options to add new components to your existing application, 329 including the previously mentioned activities as well as the following additional items:</p> 330 331 <p>To use Android object templates:</p> 332 333 <ol> 334 <li>Right click the project folder of the Android application where you want to add a code 335 component.</li> 336 <li>Select <strong>New > Other...</strong></li> 337 <li>Select <strong>Android > Android Object</strong>, and click <strong>Next</strong>.</li> 338 <li>Select an object template, then follow the instructions to add it to your existing 339 application. 340 <ul> 341 <li>{@link android.content.BroadcastReceiver}</li> 342 <li>{@link android.content.ContentProvider}</li> 343 <li><a href="{@docRoot}guide/topics/ui/custom-components.html">Custom View</a></li> 344 <li>{@link android.app.Service}</li> 345 </ul> 346 </li> 347 </ol> 348