Android Development Basics Guide
Android Development Basics Guide
Mobile Devices
Theoretical Material
Introduction to Android development
Tools for Android SDK development
Basic packages and classes for development and layouts
Text Review:
Prof. Ms. Douglas Almendro
Textual Review:
Professor Ms. Luciene Oliveira da Costa Santos
Introduction to Android development
Tools for Android SDK development
Basic packages and classes for development and layouts
Introduction
• Android Architecture
Google Play
Play Store
The evolution of the Android platform
• Criando um projeto no Android Studio.
Understanding the [Link] class
The tags of .xml files of Android
References
LEARNING OBJECTIVE
Introduce development for Android;
Explain and demonstrate the ways to create a mobile app;
GUIDELINES
Dear student,
The purpose of this unit is to install and configure Android Studio and the study
of creating a program for mobile devices using the concepts
initial layout and some basic classes to perform the proposed tasks
in this unit.
Don't forget to also watch the narrated presentation of the content and of
some solved exercises.
Good study!
Introduction to Android development
UNIT Tools for Android development SDK
Basic packages and classes for development and layouts
Contextualization
Why develop for Android?
First of all, because it is completely free, that is, you do not need
buy tools, APIs or any types of software to develop for
Android, neither a specific platform nor even a phone or gadget with
Android. Just download the SDK, an IDE and start developing.
Need more information? Just check the Android Market and see the variety of
Apps that exist out there and imagine that your Apps could be there too and still
with the possibility of earnings!
Anyway...
Are you curious? Let's roll up our sleeves and see what to develop for
mobile is not a seven-headed beast.
Good study!
6
Introduction
The processing power of mobile phones and other mobile devices today is
they are quite advanced and with this advancement, there are also noticeable improvements in
fabrics and the usability of these devices.
For these reasons, mobile platforms like Blackberry, iOS, and Android are
increasingly in evidence and the market is rising. The explosion of Android is the
the most recent among these platforms, and its increasingly larger growth.
The most used language to create apps for the little robot is Java and
we will adopt it in our classes, where we will be able to control the device via
libraries developed by Google.
7
Introduction to Android development
UNIT Tools for Android SDK development
Packages and basic classes for development and layouts
The Java language is used to build applications for Android. But not
existe uma máquina virtual Java (JVM). Na realidade, o que existe é uma máquina
Dalvik virtual call that is optimized for execution on available mobile devices.
Android has been available as open source since October 21, 2008.
Google published all the code under the ASF (Apache Software Foundation) license.
that allows changes to be made to the source code to create products
customized without needing to share the changes with anyone. However,
it depends on an authorization from Google itself to be able to access the library
from applications, Play Store.
Android architecture
The architecture of Android is composed of several layers and components, such as
it is possible to visualize in the figure below:
Figure 2
8
In the Linux Kernel layer, the platform's operating system is located,
which is based on Linux. It is responsible for lower-level services of the
platform, such as memory and process management, security, etc.
In the Libraries layer, there are native libraries written in C/C++ that
are part of the platform. APIs such as OpenGL ES (for
3D rendering), SQLite (database manager) and support for various
audio and video formats.
The Android Runtime layer provides conditions for applications based on the
platforms are executed. One of the components of this layer is the core
libraries that provide a Java API used for programming (largely
the functionalities found in Java SE are available for Android). Already
the other component is the Dalvik Virtual Machine, which is a virtual machine for
support for the execution of applications.
The Application Framework layer contains the Android APIs that are
normally used by the applications running on the platform.
The managers of telephone services, location, and notification are some
examples of what this framework provides.
Google Play
Applications developed for Android can be made available by
through a personal server, being the most common and professional done by
Google Play.
Google Play applications are available for free or at a cost, for the
Android operating system, and can be downloaded directly to a device
mobile or on a personal computer through your website.
9
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Figure 3
Play Store
The application for the Android system that allows access to the content is called
Play Store.
The Google Play apps are available in various countries, potentially being
downloaded through the Google Play website or the Android app.
Figure 4
10
The evolution of the Android platform
Figure 5
Each platform has an identifier code (API Level) and some have names.
of code.
• API Level 1 = Android 1.0
• API Level 2 = Android 1.1
• API Level 3 = Android 1.5 (Cupcake)
• API Level 4 = Android 1.6 (Donut)
• API Level 5 = Android 2.0
• API Level 6 = Android 2.01
• API Level 7 = Android 2.1 (Eclair)
• API Level 8 = Android 2.2 (Froyo)
• API Level 9 = Android 2.3 (Gingerbread)
• API Level 10 = Android 2.3.3
• API Level 11 = Android 3.0 (Honeycomb)
• API Level 12 = Android 3.1 (Honeycomb)
• API Level 13 = Android 3.2 (Honeycomb)
• API Level 14 = Android 4.0 (Ice Cream Sandwich)
• API Level 15 = Android 4.03
• API Level 16 = Android 4.1 (Jelly Bean)
• API Level 17 = Android 4.2 (Jelly Bean)
• API Level 18 = Android 4.3 (Jelly Bean)
• API Level 19 = Android 4.4 (KitKat)
• API Level 20 = Android 4.4W
• API Level 21 = Android 5.0 (LOLLIPOP)
11
Introdução ao desenvolvimento para Android
UNIT Tools for Android development SDK
Basic packages and classes for development and layouts
Figure 6
Figure 7
Data: May 2015. Source:[Link]
12
To install the tool along with Android, follow the following
procedures:
• Accessthewebsite[Link] and download theAndroid Studio package.
Figure 8
Before configuring Android Studio, make sure you have installed JDK 6 or higher.
(only the JRE is not sufficient).
JDK 7 is required to develop for Android version 5.0 and above.
The same can be obtained at the address: (Check if your operating system is for
32 or 64 bits.
[Link]
Figure 9
13
Introduction to Android development
UNIT Tools for Android development SDK
Basic packages and classes for development and layouts
Figure 10
• In this file, the module for development (Android Studio) already exists and the
Android SDK, but only the latest Android API is installed.
• After installation, run Android Studio, where we will install the others.
Android packages.
Figure 11
Figure 12
14
When running the SDK Manager, add everything from Android and install the updates.
Figure 13
Figure 14
Select all items and accept the license and select Install.
In the future, you will be able to add more packages if needed, using the
menu Tools – Android – SDK Manager.
15
Introduction to Android development
UNIT Tools for Android SDK development
Packages and basic classes for development and layouts
Figure 15
Figure 16
Figure 17
An Android project contains all the files that make up the source code.
from your Android application. The tools in Android Studio make it easier
start a new Android project with a set of 'standard directories' from
project and files.
In this lesson, we will create a new project using Android Studio. We will
set up the location where our projects will be created and the name of our project.
For this first example, we will name it HelloWorld.
16
To create a project, follow the instructions below:
1. Select Start a new Android Studio project.
Figure 18
2. In the window that appears, type the project location and the name of the
application as below:
Figure 19
17
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
• Company Domain: it's the package namespace for your application (following
the same package rules in the Java programming language). Your
package name must be unique among all installed packages in the system
Android. For this reason, it is generally better if you use a name that
start with the reverse domain name of your organization or entity
editor. For this project, you can use something like '[Link]'.
However, you cannot publish your app on Google Play using the
[Link] namespace.
3. Select project for Phone and the minimum SDK version.
Figure 20
Minimum Required SDK is the lowest version of Android that the application supports, indicated
using the level API. To support as a possible device, you must define this to
the smallest available version that allows your application to provide its set
of resources from the core. If any resource of your application is only possible in versions
most recent of Android and that is not fundamental for the application of the set of
core resources, you can enable the feature only when running on versions
that support (as discussed in support for different platform versions). Leave this
set for the default value for this project.
18
4. Now, you can select an activity template to get started.
to build your application. For this project, select BlankActivity and
click Next.
Figure 21
Figure 22
19
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Figure 23
Figure 24
20
The project's structure can be viewed using Project.
Figure 25
21
Introdução ao desenvolvimento para Android
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Figure 26
Note, however, that this class should not be manually altered. It is just
a resource that Android provides to facilitate the reference to visual objects,
images, strings etc.
Note also that our Java classes, to access any declared resource
in the res/ folder, we refer to the public attributes of this strange class
R. For example:
Images:
• [Link]
Access to files:
• [Link]
• [Link]
Access to strings:
• [Link].app_name
• hello
We will often see code that takes these components, strings, ima-
People through the findViewById method, to then use them, define listeners, etc.
This R class is generated by the Android Studio plugin and should not be modified.
altered values. It will be used as a reference to access the various
components of our inter4face. It's like a large collection of identifiers,
that the platform will know how to use to locate its values and properties of
optimized way.
22
The [Link] is generated according to the various files used for
configuration of your application. If there is any error in these files, it is likely
that the plugin cannot control it, thus propagating an error in
that all your source files. We should then be careful to look for the error
what is preventing your generation, and be careful not to import the class
android.R, which is not from your application, but rather an internal one used by Android.
Layouts
The shape and arrangement with which the elements are presented on the screen are of
responsibility of the Layouts.
The most common layouts for organizing interface elements on the screen are:
LinearLayout, RelativeLayout, and TableLayout. We will talk more about these types
of the layouts further ahead.
Figure 27
Let's replace the TextView above with the data below to understand the
use of strings:
<RelativeLayout xmlns:android=[Link]
apk/res/android
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
23
23
Introduction to development for Android
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
TextView
android:layout_width="fill_parent"
android:layout_height=”wrap_content”
android:text=”@string/hello_world”
/>
</RelativeLayout>
The TextView tag has a height determined only as necessary to display its.
content, set as wrap_content.
Figure 28
This is a simple idea, but it makes the internationalization of your application easier.
thus being able to be introduced to other languages, just by creating other files
devalues translations.
Selecting the graphic mode, we will notice how the layout looks.
Figure 29
24
Emulator configuration
After installing the platform and the image for each version of Android, the
The next step is to create the emulator(s) to test our applications.
Figure 30
Figure 31
On the new AVD selection screen, we can use various resolutions, and for
In our classes, we will use the Nexus 4 with a resolution of 768 x 1280 pixels, as per
below screen.
25
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Figure 32
Our next setup is the version of Android, and for our class we will
use the KitKat version, that is, Android 4.4.2. If it is not installed,
Select the Download so that it can be part of our project.
Figure 33
26
Após o Download, selecione a versão do Android 4.4.2 (KitKat) e selecione o
Next button.
Figure 34
Figure 35
27
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Figure 36
Soon, our emulator is already operating and can now receive our first
application.
Figure 37
28
Now, we will run our AloMundo application. Select the figure below.
para executar nossa aplicação.
Figure 38
Figure 39
Figure 40
29
Introduction to Android Development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
The system will compile the application and, after a few seconds, our will be opened.
application in the emulator that we had started.
Figure 41
If you want to stop the application, select the item below Android and the item
Terminate Application.
Figure 42
Fundamental concepts
Let's understand now the components and their life cycles so that we can
build a robust, expandable system with acceptable performance for
the user.
30
Components of an Android Application
Developing applications for Android means composing a series of components.
so that the final objective of the application is achieved. The figure below shows these
components.
Figure 43
Activities are the representatives of the application screens. Associated with an activity
there is normally a view that defines how the visual display will be made for the
User. The activities are responsible for managing screen events and also
coordinate the application's flow.
Every Activity has a life cycle represented in the figure below. The methods
called will be the methods that we will override when we create our
own Activities.
31
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Figure 44
onCreate()
It is the first function to be executed in an Activity. Generally, it is responsible
for loading the XML layouts and other initialization operations. It is executed
only once.
onStart()
It is called immediately after onCreate() - and also when an Activity
what was in the background regains focus.
onResume()
Just like onStart(), it is called during the initialization of the Activity and also
when an Activity regains focus. What is the difference between the two? The onStart()
is only called when the Activity was no longer visible and returns to having focus, the
onResume() is called on 'focus resumption'.
32
onPause()
It is the first function to be invoked when the Activity loses focus (this happens
when a new Activity is started).
onStop()
It is only called when the Activity is completely covered by another
Activity.
onDestroy()
The last function to be executed. After that, the Activity is considered 'dead' -
that is, it can no longer be relaunched. If the user requests this Activity again,
a new object will be built.
Services are codes that run in the background. They are typically used
for tasks that require a long execution time.
Content Providers are the way used by
platform for sharing data between the applications running on the device.
A clear example of this is the Android contact management application.
what is native. Third-party applications can use a content
provider to read the contacts stored on the device simply.
Broadcast Receivers are components that 'listen' for the occurrence of
certain events, which can be native or triggered by applications. A
the application can, for example, use a broadcast receiver to be notified when
the device is receiving a call and, based on this information, perform
some type of processing.
Yes, there is the figure of Android Core, which is actually not a component.
specific, but rather the Android platform itself.
He is the one who provides the interaction between the components and the applications.
makes it possible to execute the code.
Screen components:
All Android screens are made in an XML file, which is located within
res/layout, where the details of each component are configured. A component
it is a graphic item.
33
33
Introduction to Android development
UNIT Tools for Android SDK development
Packages and basic classes for development and layouts
View is the basic class that allows you to build interface components. A
View occupies a rectangular area on the screen and is responsible for drawing and serving
events, if necessary.
Figure 45
Some people will call these components widgets, but there is another
concept in android, which is a small application that can run within the home
of the mobile device, also called a widget.
The most common interface components are created with the classes
TextView, EditText, Button, RadioButton, RadioGroup, CheckBox, etc., all
derived directly or indirectly from the View class.
34
Below are some of the most commonly used components, their properties and al-
guns listeners:
TextView
It is used to write a text on the Android screen, like a label.
The TextView is used to display text to the user, just like the JLabel does.
Swing. We can control its appearance and size via XML, just modify the
attributes in the TextView tag, some of these attributes are:
• android:text:value will be the text of the component;
For example, if we want the text in bold we use 'bold', in italics we use
the value "italic", but if we want the text to be bold+italic, we can use the
pipe joining the two: "bold|italic".
Figure 46
35
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
EditText
WhiletheTextViewdisplaystextlikeaJLabel,whoprovidestheuserwithacam-
TheplaceforhimtoentertextistheEditText(justliketheJTextField)whichisachildofTextView.
This component does not declare any new XML attributes, but uses those from
TextView, the difference is that it actually allows editing.
Figure 47
Button
It is a simple button with something written just like the JButton. It is through it
that the user knows that some action will be taken when clicking.
36
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=[Link]
android
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/textView">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=”Hello Views!”
android:textSize="28px"
android:textColor=”#12FF88”
android:textStyle="italic|bold" />
<EditText android:id="@+id/editView">
android:layout_width="match_parent"
android:layout_height=”wrap_content”
android:text=”...”
android:textSize=”28px”
android:textColor=”#12FF88”
android:textStyle=”italic|bold” />
<Button android:id="@+id/button">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=”Click!”
android:textSize="28px"
android:textColor=”#12FF88”
android:textStyle=”italic|bold” />
</LinearLayout>
Figure 48
CheckBox
It is a button that allows the user to toggle between the checked/unchecked options.
unchecked.
It also extends TextView, and the value assigned in 'android:text' is the text
visible next to the CheckBox.
37
Introduction to development for Android
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
ToggleButton
ToggleButtons are buttons like CheckBoxes, but indicate checked/unchecked
with a 'light' instead of the drawing effect of a 'tick'. The 'android:text' attribute
it has no effect on this component, by default the text is alternated between ON and
OFF, making it possible to use attributes such as color, style, size, etc. to modify
the appearance of this text.
RadioButton
They are buttons like the CheckBox that allow you to mark it, but it is not possible.
uncheck it. To achieve the effect of single selection, it is necessary to add them to
a RadioGroup.
38
android:textSize="28px" android:textCol-
or="#12FF88" android:textStyle="italic|bold" />
<ToggleButton android:id="@+id/tbutton"
android:layout_width="match_parent" android:lay-
out_height=”wrap_content”
android:textOn=”Ligado” android:textOff=”De-
sligado" android:textSize="28px"
android:textColor="#12FF88" android:text-
Style="italic|bold" />
<RadioGroup android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButtonandroid:id=”@+id/r1button”
android:layout_width="match_parent" an-
droid:layout_height="wrap_content"
Option 1
Size=”28px” android:textColor=”#12FF88”
android:textStyle="italic|bold" />
<RadioButton android:id="@+id/r2button"
android:layout_width="match_parent" an-
droid:layout_height="wrap_content"
Option 2
Size=”28px” android:textColor=”#12FF88”
android:textStyle="italic|bold" />
</RadioGroup>
</LinearLayout>
Note that all of them have the attributes of TextView, making it easy to customize them.
Figure 49
ImageView
The ImageView, as the name suggests, is a component that allows us to
working with images.
39
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Putting images in Android becomes very simple with your drawable folder, because
If it does not exist, it simply does not map in [Link].
ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src=”@drawable/ic_launcher” />
As we have seen, there must be the image within res/drawable, and from the
Android 1.6, this folder allows for 3 different resolution versions.
Figure 50
LinearLayout
LinearLayout is one of the simplest layouts. It arranges the elements inside
delete in a linear way, either horizontally or vertically.
To assist with our examples, we will create another layout file. With the
right-click on layout, select New - XML - Layout XML File.
40
Figure 51
Figure 52
41
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Figure 53
Now, we will replace the generated code with the one described below:
<TextView
android:id=”@+id/textView2”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
I am
android:textSize=”20sp”/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Learning
android:textSize=”20sp”/> Screen components
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Android
android:textSize=”20sp”/>
<ImageView
android:id=”@+id/imageView1”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src=”@mipmap/ic_launcher”/>
42
<ImageView
android:id="@+id/imageView2"
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@mipmap/ic_launcher”/>
</LinearLayout>
Figure 54
Figure 55
If you want to practice more, use the Widgets in the window next to you and drag.
for the device to check how it will look.
Also change the layout orientation to horizontal and see how it will look.
arrangement of objects. We can also define the strategy for width and height
of items: fill_parent or wrap_content (fill-fill; wrap-wrap, roll).
43
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Replace the layout above with the one below and see the result:
Figure 56
TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
I am
TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text=”Aprendendo”android:textSize=”22sp”/>
TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text=”Android”android:textSize=”22sp”/>
<ImageView
android:id=”@+id/imageView1”
android:layout_width="wrap_content"
44
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@mipmap/ic_launcher"/>
<ImageView
android:id=”@+id/imageView2”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@mipmap/ic_launcher
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:src="@mipmap/ic_launcher"/>
</LinearLayout>
Table Layout
In this type of layout, we place items in rows and columns. Attributes
Common ones are: padding (cell spacing) and gravity (alignment). See
android:stretchColumns="0,1" (columns to be "stretched"; use * for all).
The unit used is dip (Density-independent pixel), see more details at:
[Link]
[Link]
Example of TableLayout:
Figure 57
45
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Figure 58
<TableRow>
TextView
Line 2 - Column 1
android:padding="3dip"/>
TextView
Line 2 - Column 2
android:gravity="right"
android:padding="3dip"/>
</TableRow>
</TableLayout>
46
Units that can be used for the dimensions:
Figure 59
RelativeLayout
As the name itself says, the Relative Layout is relative. But what does this mean?
What does it mean? Unlike the Linear Layout, which always specifies a direction.
horizontal or vertical, in the relative layout, we position the elements by reference
to other elements. For example, we say if the button will be below a field
of text, on the right side or even above it.
47
Introduction to Android Development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Figure 60
48
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text=”Cancel”/>
</RelativeLayout>
For this example, we will split the layouts into 2 files. Firstly,
we will create a layout file below with the name: listview_item.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:padding="5dip"
TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine=”true”
android:textSize="28sp"
android:textStyle="bold"
android:textColor=”#0000ff”/>
</LinearLayout>
TextView
android:id="@+id/tvMsg"
android:layout_width="wrap_content"
49
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:textColor=”#ebebeb”
android:textSize=”20sp”
android:textStyle=”bold”/>
</RelativeLayout>
We will create the second layout file named layout_linear2 and we will
reference within it the file created above, as per the example below:
<LinearLayout xmlns:android=[Link]
apk/res/android
xmlns:tools=”[Link]
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background=”#ebebeb”
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop=”15dp”
android:background=”#990000”
android:orientation=”vertical”>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background=”#990000”
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text=”Menu”
android:textAppearance="?android:attr/
textAppearanceLarge
android:textColor=”#00ff00”
android:textSize=”25sp”
android:textStyle=”bold”/>
<Button
50
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dip"
android:width="150px"
android:height=”60px”
android:textStyle="bold"
Button/>
</LinearLayout>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom=”10dp”
tools:listitem=”@layout/listview_item”>
</ListView> Reference
</LinearLayout> to the file
generated above
</LinearLayout
Perceba que podemos ter vários tipos de layouts, inclusive um dentro do outro.
We can also create separate layout files and perform the reference within.
from another layout file. The result will be the layout below:
Figure 61
If you want to better organize the colors, we can create an xml file of
colors and make the reference within the files created above. To do this, create a
XML file named "mycolor" will be available in the values folder.
as below and set your colors:
51
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Figure 62
Now, we can replace the hexadecimal color code with the nomenclature
created above, as per the example below:
Replaceandroid:textColor=”#0000ff”forandroid:textColor="@color/
blue
Figure 63
52
In the [Link] program, change the call to the new in the onCreate method.
layout, as below:
Figure 64
Now, run the project again and see how it will look on the emulator screen.
device.
If you have closed the emulator, when you run it, the screen below will open, but since you have already
we configured the emulator earlier, just select the Android virtual device
and the OK button.
Figure 65
53
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Figure 66
Remember that we have created all the layouts below and, if you wish, we can
change to any of these created and run the project again.
Figure 67
54
Figure 68
The options will be consulted for detailed help from a component class.
of the interface (again we use TextView as an example). Note, in the part
below the figure, the list of XML attributes, their names and related methods.
Figure 69
55
Introduction to Android development
UNIT Tools for Android SDK development
Packages and basic classes for development and layouts
It's worth remembering that we can generate various types of layouts, and it depends on creativity.
the need of each one in order to develop a more improved layout.
Below, some examples of more sophisticated layouts:
Figure 70
Figure 71
56
Figure 72
57
Introduction to Android development
UNIT Tools for Android SDK development
Basic packages and classes for development and layouts
Complementary Material
Indications to learn more about the topics covered in this Unit:
Sites
Layouts
[Link]
Table
[Link]
Compatibility with multiple screens
[Link]
Relative Layout
[Link]
58
References
[Link] DevelopersAvailable at [Link]
59