Professional Documents
Culture Documents
Mobile Application Development
Mobile Application Development
Mobile Application Development
Development
Android
1
Introduction to Android
2
Android Software Developer Kit (SDK)
3
Create Your First Android App
Prerequisites
Java Programming Language
Object-oriented programming
XML - properties / attributes
Using an IDE for development and debugging
4
Android Studio
● Android IDE
● Project structure
● Templates
● Layout Editor
● Testing tools
● Gradle-based
build
● Log Console
● Debugger
● Monitors
● Emulators
5
Creating Your First Android App(Start Android Studio)
6
Create a project inside Android Studio
7
Name your app
8
Pick activity template
9
Name your activity
● Use AppCompat
10
Android Studio Panes
Layout
Editor
Project
Files
Android Monitors:
logcat: log messages
11
Project folders
1. Manifests:
Android Manifest file -
description of app read by the
Android runtime
2. Java:
Java source code packages
3. Res:
Resources (XML) - layout,
strings, images, dimensions,
colors...
4. build.gradle:
Gradle build files
12
Gradle build system
13
Run your app
1. Run
2. Select virtual
or physical
device
3. OK
14
Create a virtual device
Use emulators to test app on different versions of Android and form factors.
15
Configure virtual device
16
Run on a virtual device
17
Run on a physical device
Windows drivers:
● OEM USB Drivers
18
Xml in android
19
Basics Of User Interface:
20
Different XML Files Used in Android:
1. Layout XML Files:
Layout xml files are used to define the actual UI(User interface)
of our application.
It holds all the elements(views) or the tools that we want to use
in our application.
Like the TextView’s, Button’s and other UI elements.
21
What is a view
22
Views have properties
23
Examples of views
24
Creating and laying out views
XML Files
Programmatically
25
Views defined in Layout Editor
26
View properties in XML
android:<property_name>="<property_value>"
Example: android:layout_width="match_parent"
android:<property_name>="@<resource_type>/resource_id"
Example: android:text="@string/button_label_next"
android:<property_name>="@+id/view_id"
Example: android:id="@+id/show_count"
27
ViewGroup & View Hierarchy
28
Hierarchy of view groups and views
29
View hierarchy and screen layout
30
Best practices for view hierarchies
31
Basic Layout XML Code:
Below we show activity_main.xml file in which we have two TextView’s.
32
2. Manifest xml File(Mainfest.xml):
This xml is used to define all the components of our application.
It includes the names of our application packages, our Activities,
receivers, services and the permissions that our application needs.
For Example – Suppose we need to use internet in our app then we need to
define Internet permission in this file.
Below we show the AndroidManifest.xml file and define the Internet Permission in that file.
33
3. Strings xml File(strings.xml):
This xml file is used to replace the Hard-coded strings with a single string.
We define all the strings in this xml file and then access them in our app(Activity
or in Layout XML files) from this file.
This file enhance the reusability of the code.
34
4. Styles xml File(styles.xml):
This xml is used to define different styles and looks for
the UI(User Interface) of application.
We define our custom themes and styles in this file.
35
5. Drawable xml Files:
These are those xml files that are used to provide various graphics to the
elements or views of application.
When we need to create a custom UI we use drawable xml files.
Suppose if we need to define a gradient color in the background of Button or
any custom shape for a view then we create a Drawable xml file and set it in
the background of View.
36
6. Color xml File (colors.xml):
This file is used to define the color codes that we used in our app.
We simply define the color’s in this file and used them in our app from
this file.
37
7. Dimension xml File(dimens.xml):
This xml file is used to define the dimensions of the View’s.
Suppose we need a Button with 50dp(density pixel) height then
we define the value 50dp in dimens.xml file and then use it in
our app from this file.
38
Layouts
39
Common Layout Classes
40
Common Layout Classes
41
Linear Layout
Linear layout is a simple layout used in android for layout
designing.
In the Linear layout all the elements are displayed in linear
fashion means all the childs/elements of a linear layout are
displayed according to its orientation.
The value for orientation property can be either horizontal or
vertical.
Types Of Linear Layout Orientation
There are two types of linear layout orientation:
1. Vertical
2. Horizontal
Vertical:
In this all the child are arranged vertically in a line one after the other.
In below code snippets we have specified orientation “vertical” so the
childs/views of this layout are displayed vertically.
42
43
Horizontal:
In this all the child are arranged horizontally in a line one after
the other.
In below code snippets we have specified orientation
“horizontal” so the childs/views of this layout are displayed
horizontally.
44
Main Attributes In Linear Layout:
orientation: The orientation attribute used to set the
childs/views horizontally or vertically. In Linear layout default
orientation is vertical.
gravity: The gravity attribute is an optional attribute which is
used to control the alignment of the layout like left, right,
center, top, bottom etc.
45
layout_weight: The layout weight attribute specify each child
control’s relative importance within the parent linear layout.
46
weightSum: weightSum is the sum up of all the child
attributes weight. This attribute is required if we define
weight property of the childs.
47
Example of Linear Layout:
Now lets design 2 linear layout UI. First we have designed using
weight attribute and second without using it. So below layout output
will clear the difference between them:
48
Example 1: First we will design Android Linear Layout without using weight
property. In this example we have used one TextView and 4 Button. The
orientation is set to vertical.
49