Android Application
Development
Lesson 6
Android Layouts, Styles, Theme
and Menus
Views
Layouts
• Constraint Layout
• Linear Layout
• Relative Layout
• TableRow Layout
• Frame Layout
• ScrowView Layout
Android Styles and Themes
• Android Styles
• Android Themes
App Manifest
Lab 6: Android Application Layouts, Styles, and Themes
• Create Your Application Layout
• Configure Your Styles and Themes
• Configure Your App Icon
Views
A view in Android applications is the basic component for a user-
interface. In Android SDK, the class is called View. It is the highest-
level class for any user interface component or widget you may use
in your applications. All user interface widgets that you have seen
before like Button and TextView are subclasses of class View.
Layouts
A layout defines the visual structure for a user interface, such as the
user interface for an activity or app widget. You can declare a layout in
two ways:
1- Declare user elements in XML: Android provides a
straightforward XML vocabulary that corresponds to the View
classes and subclasses, such as those for widgets and layouts.
2- Instantiate layout elements at runtime: Your application
can create View and ViewGroup objects (and manipulate their
properties) programmatically.
Layout Types
Constraint Layout:
Constraint Layout is a powerful new layout
engine released as a part of Constraint
Layout library in Android Studio 2.2 and later
versions. It is fully integrated with Android
Studio’s layout editor so you can build the
full layout without the need to edit the XML
manually.
This layout allows us to specify constraints
that would decide the position of each sub
element within the layout.
Check the example on page 6-2
Layout Types
Linear Layout
A Linear Layout is a layout that arranges other views either
horizontally in a single column or vertically in a single row.
Check the example on page 6-6
Layout Types
Relative Layout
The RelativeLayout
arranges widgets in
positions relative to each
other. For example, you
may position a button on
the layout to the left,
right or on top of
another button.
Check the example on page
6-10
Layout Types
Table Layout
Table Layout arranges views into rows and columns.
<TableLayout
android:layout_width="368dp"
android:layout_height="495dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
Check the example on page 6-15
Layout Types
ScrollView Layout
ScrollView is a view group that allows the view hierarchy placed within it to
be scrolled.
<ScrollView
android:layout_width="wrap_content" Scroll
android:layout_height="40dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="16dp"
android:text“ x x x x x x x " />
</ScrollView>
Check the example on page 6-19
Android Styles and Themes
Building your Android application
requires more than just writing a
Kotlin code. As you have already
seen, you need to build the layout
of your activities to provide the
user interface. These layout files
are XML files saved under
/res/layout and are just one
example of the many resource files
you may add to your Android
If you need static and contact data
application.
(images, strings…etc.), you should
add them as resources in your
application i.e. externalize them.
Adding your application’s resources in
a separate folder improves your
development experience and yields a
more robust application for several
reasons such as maintaining and
debugging your application .
Android Styles
Android style is a collection of
attributes that specifies the look and
format of a View or window. A style can
specify attributes such as height,
padding, font color, font size,
background color, and much more. A
style is defined in an XML resource
separate from the XML that specifies
the layout.
Check the example on page 6-22
Android Themes
When a resource is used to define the
style of the whole activity or
application, it is called a theme. This is
available for apps that target Android [Link]
5.0 (API level 21) or higher.
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category
android:name="[Link]" />
</intent-filter>
</activity>
</application>
Check the example on page 6-31
Adaptive Icons
Android 8.0 (API level 26) introduces adaptive launcher icons, which
can display a variety of shapes across different device models. Each
device provides a mask, which the system uses to render all the
adaptive icons of the same shape. An adaptive launcher icon is also
used in shortcuts, settings app, sharing dialogs, and the overview
screen
Check the example on page 6-37
Lab 6
Android Application Layouts, Styles
and Themes
Objectives:
Create Your Application
Layout
Configure Your Styles and
Themes
Configure Your App Icon
Open Page 6-41 in Android Application Development book v8
and Start
your lab step by step.