Professional Documents
Culture Documents
In this document
Add a project component
Select an activity template
Basic Activity
Empty Activity
Fullscreen Activity
Login Activity
Master/Detail Flow
Scrolling Activity
Settings Activity
(https://developer.android.com/studio/projects/create-
Tabbed Activity
project.html),
In addition to activities, you can also add other Android project components to an
existing app using templates. These templates include both code components,
such as services and fragments, and non-code components, such as folders and
XML les.
This page discusses how to add Android project components like activities to your
project and describes the commonly used activity templates available in Android
Studio. Note that most templates depend on the Android Support Library
(https://developer.android.com/tools/support-library/features.html)
window.
Right-click on the folder in which you want to add the new component, and select
New. Based on what components can be added to the folder you clicked on, you
then see a list of template types like those shown in gure 1.
When you select the template you want to add, a corresponding wizard window
appears and asks for the component's conguration information, such as its name.
After you enter the conguration information, Android Studio creates and opens the
les for your new component. It also runs a Gradle build to sync your project.
Although you can also use the File > New menu of Android Studio to create a new
Android project component, navigating to your desired folder in the Project window
ensures that you create the component in the correct place.
This section covers the commonly used activity templates for phone and tablet
apps. Android Studio also provides templates for a variety of different app module
types, including Android Wear, Android TV, and Cloud App Engine. You can view
templates for these different module types when creating an app module
(#CreateAppModule).
Basic Activity
This template creates a simple app with an app bar and a oating action button. It
acts as a starting point for your project by providing commonly used UI
components.
This template includes:
AppBar
(https://developer.android.com/training/appbar/index.html)
FloatingActionButton
(https://developer.android.com/reference/android
/support/design/widget/FloatingActionButton.html)
Two layout les: one for the activity and one to separate out text content
Empty Activity
This template creates an empty activity and a single layout le with sample text
content. It allows you to start from scratch when building your app module or
activity.
This template includes:
Single layout le with text content
Fullscreen Activity
This template creates an app that alternates between a primary fullscreen view and
a view with standard user interface (UI) controls. The fullscreen view is the default
and a user can activate the standard view by touching the device screen.
This template includes:
(https://developer.android.com/training/appbar/index.html)
for the
standard view
Single layout le with both the fullscreen view and a frame layout for standard
view elements
Login Activity
This template creates a standard login screen. The user interface includes email
and password elds and a sign-in button. It is more commonly used as an activity
template than as an app module template.
This template includes:
AsyncTask
(https://developer.android.com/reference/android/os/AsyncTask.html)
implementation for handling network operations separately from the main user
interface thread
Progress indicator during network operations
Single layout le with the recommended login UI:
Email and password input elds
Sign-in button
Master/Detail Flow
This template creates an app that has both an item list display and a display for the
details of an individual item. Clicking on an item on the list screen opens a screen
with the items details. The layout of the two displays depends on the device that is
running the app.
This template includes:
Activity representing the list of items
Activity and fragment options for displaying an individual items details
FloatingActionButton
(https://developer.android.com/reference/android
/support/design/widget/FloatingActionButton.html)
on each screen
This template creates a Basic Activity with a navigation drawer menu. The
navigation bar expands from the left or right side of your app and appears in
addition to the regular app bar.
This template includes:
Navigation drawer implementation with a DrawerLayout
(https://developer.android.com/reference/android/support/v4/widget
/DrawerLayout.html),
AppBar
(https://developer.android.com/training/appbar/index.html)
FloatingActionButton
(https://developer.android.com/reference/android
/support/design/widget/FloatingActionButton.html)
Layout les for the navigation drawer and the navigation drawer header, in
addition to those from the Basic Activity template
Scrolling Activity
This template creates an app with a collapsing toolbar and a scrolling view for long
text content. As you scroll down the page, the toolbar, which can serve as a header,
automatically condenses, and the oating action button disappears.
This template includes:
Collapsing toolbar (https://developer.android.com/reference/android/support/design/widget
/CollapsingToolbarLayout.html)
(https://developer.android.com/training/appbar/index.html)
FloatingActionButton
(https://developer.android.com/reference/android
/support/design/widget/FloatingActionButton.html)
Two layout les: one for the activity and one to separate out the text content into
a NestedScrollView
(https://developer.android.com/reference/android/support
/v4/widget/NestedScrollView.html)
Settings Activity
PreferenceActivity
(https://developer.android.com/reference/android/preference
/PreferenceActivity.html)
(https://developer.android.com
/reference/android/preference/PreferenceActivity.html)
XML les (in the res/xml/ directory of your project) to dene the displayed
settings
Tabbed Activity
sections are dened as fragments between which you can swipe left and right to
navigate.
This template includes:
AppBar
(https://developer.android.com/training/appbar/index.html)
(https://developer.android.com
/reference/android/support/v4/app/FragmentPagerAdapter.html)
and creates a
(https://developer.android.com/reference/android/support/v4/view
/ViewPager.html)
Two layout les: one for the activity and one for individual fragments