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