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