SlideShare a Scribd company logo
Apache 2 license
This work is licensed under the Apache 2 license.
Apache 2 license
This work is licensed under the Apache 2 license.
Android Development with Kotlin v1.0 1
Lesson 13:
App UI design
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
About this lesson
Lesson 13: App UI design
● Android styling
● Typography
● Material Design
● Material Components
● Localization
● Example apps
● Summary
2
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license. 3
Android styling
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Android styling system
4
● Used to specify the visual design of your app
● Helps you maintain a consistent look across your app
● Hierarchical (you can inherit from parent styles and override
specific attributes)
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Precedence of each method of styling
5
View
attributes
Style
Theme
Overrides this
Overrides this
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Themes
● Collection of named resources, useful broadly across the app
● Named resources are known as theme attributes
● Examples:
○ Use a theme to define primary & secondary colors in the app
○ Use a theme to set the default font for all text within an activity
6
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Declare a theme
7
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
<item name="colorPrimary">@color/orange_500</item>
<item name="colorPrimaryVariant">@color/orange_700</item>
<item name="colorSecondary">@color/pink_200</item>
<item name="colorSecondaryVariant">@color/pink_700</item>
...
</style>
In res/values/themes.xml:
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Apply a theme
<manifest ... >
<application ... >
<activity android:theme="@style/Theme.MyApp" ... >
</activity>
</application>
</manifest>
8
In AndroidManifest.xml:
In layout file:
<ConstraintLayout …
android:theme="@style/Theme.MyApp">
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Refer to theme attribute in a layout
Use ?attr/themeAttributeName syntax.
Examples: ?attr/colorPrimary
?attr/colorPrimaryVariant
9
<LinearLayout …
android:background="?attr/colorSurface">
In layout file:
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Styles
● A style is a collection of view attributes, specific to a
type of view
● Use a style to create a collection of reusable styling
information, such as font size or colors
● Good for declaring small sets of common designs used
throughout your app
10
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Declare a style
11
<style name="DescriptionStyle">
<item name="android:textColor">#00FF00</item>
<item name="android:textSize">16sp</item>
...
</style>
In res/values/styles.xml:
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Apply a style
12
<TextView
style="@style/DescriptionStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/description_text" />
On a view in a layout file:
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Refer to theme attribute in a style
13
<style name="DescriptionStyle">
<item name="android:textColor">?attr/colorOnSurface</item>
<item name="android:textSize">16sp</item>
...
</style>
In res/values/styles.xml:
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
View attributes
● Use view attributes to set attributes explicitly for each view
● You can use every property that can be set via styles or themes
● Use for custom or one-off designs such as margins, paddings,
or constraints
14
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Resources directory
└── res
├── drawable
├── drawable-*
├── layout
├── menu
├── mipmap-*
├── navigation
├── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ ├── styles.xml
│ └── themes.xml
└── values-*
15
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Provide alternative resources
└── res
├── values
│ ├── colors.xml
│ ├── strings.xml
│ ├── styles.xml
│ └── themes.xml
└── values-b+es
│ ├── strings.xml
└── values-night
└── themes.xml
16
Use when device locale is set to Spanish
Use when night mode is turned on
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Color resources
A way to name and standardize colors throughout your app
17
In res/values/colors.xml:
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
...
</resources>
Specified as hexadecimal colors in form of #AARRGGBB
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Dimension resources
● Declare your dimension values in res/values/dimens.xml:
● Refer to them as @dimen/<name> in layouts or R.dimen.<name> in code:
18
<resources>
<dimen name="top_margin">16dp</dimen>
</resources>
<TextView …
android:layout_marginTop="@dimen/top_margin" />
A way to name and standardize dimension values in your layouts
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license. 19
Typography
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Scale-independent pixels (sp)
● The textual equivalent to density-
independent pixels (dp)
● Specify text sizes in sp
(takes into account user preferences)
● Users can adjust Font and Display sizes
in the Settings app (after Display)
20
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Type scale
● A set of styles designed to work
together in a cohesive manner
for your app and content
● Contains reusable categories of
text with intended purpose for
each (for example, headline,
subtitle, caption)
21
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
TextAppearance
A TextAppearance style often alters one or more of these attributes:
22
● typeface (android:fontFamily)
● weight (android:textStyle)
● text size (android:textSize)
● capitalization (android:textAllCaps)
● letter spacing (android:letterSpacing)
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Examples using TextAppearance
23
<TextView
...
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline1"
android:text="@string/title" />
<TextView
...
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
android:text="@string/body_text" />
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Customize your own TextAppearance
<style name="TextAppearance.MyApp.Headline1"
parent="TextAppearance.MaterialComponents.Headline1">
...
<item name="android:textStyle">normal</item>
<item name="android:textAllCaps">false</item>
<item name="android:textSize">64sp</item>
<item name="android:letterSpacing">0</item>
...
</style>
24
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Use a custom TextAppearance in a theme
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
...
<item name="textAppearanceHeadline1">@style/TextAppearance.MyApp.Headline1</item>
...
</style>
25
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license. 26
Material Design
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Intro to Material
Adaptable system of
guidelines, components, and
tools that support best
practices for UI design
Material Design homepage
27
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Material Components
Interactive building blocks
for creating a user interface
28
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Material color tool
29
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Baseline Material color theme
30
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Material Components for Android Library
implementation 'com.google.android.material:material:<version>'
31
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Material Themes
32
● Theme.MaterialComponents
● Theme.MaterialComponents.NoActionBar
● Theme.MaterialComponents.Light
● Theme.MaterialComponents.Light.NoActionBar
● Theme.MaterialComponents.Light.DarkActionBar
● Theme.MaterialComponents.DayNight
● Theme.MaterialComponents.DayNight.NoActionBar
● Theme.MaterialComponents.DayNight.DarkActionBar
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Material theme example
33
Theme.MaterialComponents.DayNight.DarkActionBar
Light mode Dark mode
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Dark theme
A low-light UI that displays mostly dark surfaces
● Replaces light-tinted surfaces and dark text
with dark-tinted surfaces and light text
● Makes it easier for anyone to use a device
in lower-light environments
● Improves visibility for users with low vision
and those sensitive to bright light
● Can significantly reduce power usage
(depending on the device)
34
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Support dark theme
In values/themes.xml:
35
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">@color/orange_500</item>
...
In values-night/themes.xml:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">@color/orange_200</item>
...
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license. 36
Material Components
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Material Components
Component library provided for Android and design guidelines
37
● Text fields ● App bars (top and bottom)
● Buttons ● Floating Action Button (FAB)
● Menus ● Navigation Drawer
● Cards ● Bottom navigation
● Chips ● Snackbar
...and more!
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Text field
● Composed of TextInputLayout with child view
TextInputEditText
● Shows a floating label or a text hint before the user enters text
● Two types:
38
Filled text field Outlined text field
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Text field example
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
39
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Bottom navigation
● Allows movement between top level
destinations in your app
● Alternate design pattern to a
navigation drawer
● Limited to 5 locations max
40
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Bottom navigation example
41
<LinearLayout …>
...
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/bottom_navigation_menu" />
</LinearLayout>
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Bottom navigation listener
bottomNav.setOnNavigationItemSelectedListener { item ->
when(item.itemId) {
R.id.item1 -> {
// Respond to navigation item 1 click
true
}
R.id.item2 -> {
true
}
else -> false
}
}
42
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Snackbar
● Display short messages within the app
● Messages have a duration (SHORT,
LONG, or INDEFINITE)
● May contain an optional action
● Works best in a CoordinatorLayout
● Shown at bottom of enclosing container
43
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Snackbar examples
Show a simple message:
Snackbar.make(view, R.string.text_label, Snackbar.LENGTH_SHORT)
.show()
44
Add an action to a Snackbar:
Snackbar.make(view, R.string.text_label, Snackbar.LENGTH_LONG)
.setAction(R.string.action_text) {
// Responds to click on the action
}
.show()
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Floating Action Button (FAB)
● Perform the most-common action for a screen (for example, creating a new
email)
● Come in multiple sizes (regular, mini, and extended)
45
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
CoordinatorLayout
● Acts as top-level container in an app
● Manages interaction of its child views, such as gestures
● Recommended for use with views like a Snackbar or FAB
46
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
FAB example
<androidx.coordinatorlayout.widget.CoordinatorLayout ...>
....
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:contentDescription="@string/fab_content_desc"
app:fabSize="normal" <!-- or mini or auto -->
app:srcCompat="@drawable/ic_plus"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
47
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Cards
● A card holds content and actions
for a single item.
● Cards are often arranged in a
list, grid, or dashboard.
● Use MaterialCardView.
48
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
MaterialCardView example
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
</com.google.android.material.card.MaterialCardView>
49
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView .../>
<TextView .../>
</LinearLayout>
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license. 50
Localization
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Localize your app
● Separate the localized aspects of your app (for example, text, audio
files, currency, and numbers) as much as possible from the core
Kotlin functionality of the app.
Example: Extract the user facing strings into strings.xml.
● When a user runs your app, the Android system selects which
resources to load based on the device's locale.
● If locale-specific resources are not found, Android falls back to
default resources you defined.
51
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Support different languages and cultures
● Decide which locales to support.
● Create locale-specific directories in res directory:
<resource type>-b+<language code>
[+<country code>]
Examples: layout-b+en+US
values-b+es
● Provide locale-specific resources (such as strings
and drawables) in those directories.
52
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Support languages that use RTL scripts
53
● Users can choose a language that uses right-to-left (RTL) scripts.
● Add android:supportsRtl="true" to app tag in manifest.
● Convert left and right to start and end, respectively, in your layout
files (change android:paddingLeft to android:paddingStart).
● Localize strings and format text in messages.
● Optionally, use -ldrtl resource qualifier to provide alternate resources.
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license. 54
Example apps
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Check out other apps
55
Sunflower
app
Google I/O
app
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license. 56
Summary
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Summary
In Lesson 13, you learned how to:
● Customize the visual look of your app using styles and themes
● Choose from predefined type scales for the text in your app (or create
your own text appearance)
● Select theme colors for your app using Material color tool
● Use Material Components library to speed up UI development
● Localize your app to support different languages and cultures
57
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Learn more
58
● Material Design
● Material Components
● Tools for picking colors
● Dark theme
● Localize your app
● Blog posts: Themes vs Styles, Common Theme Attributes, Prefer Theme
Attributes, Themes Overlay
● Sample code: Sunflower app, Google I/O app, Android GitHub repo
Android Development with Kotlin
Apache 2 license
This work is licensed under the Apache 2 license.
Pathway
59
Practice what you’ve learned by
completing the pathway:
Lesson 13: App UI Design

More Related Content

PDF
Android Application Development - Level 1
PPTX
DSC ASEB Android Study Jams 2020: New to Programming 3
PPTX
Android Study Jam 2
PPTX
Android session 2-behestee
PPTX
Android styles and themes
PDF
Lesson 10 Advanced RecyclerView use cases.pdf
PPT
eyeryeryeryeryeyeyeryeryyerye13872085.ppt
PDF
Android Introduction
Android Application Development - Level 1
DSC ASEB Android Study Jams 2020: New to Programming 3
Android Study Jam 2
Android session 2-behestee
Android styles and themes
Lesson 10 Advanced RecyclerView use cases.pdf
eyeryeryeryeryeyeyeryeryyerye13872085.ppt
Android Introduction

Similar to Lesson 13 App User Interface Design of movile app (20)

PPTX
Consistent UI Across Android Devices
PDF
Compose Camp 1.pdf
KEY
Android momobxl
PDF
Compose Camp 1.pdf
PPTX
DSC ASEB Android Study Jams 2020: New to Programming 1
PDF
Android application development workshop day1
PPTX
Week 5 slides
PPTX
01.2 Layouts and resources for the UI.pptx
PDF
Introduction to Android Development with Java
PDF
Android Develpment vol. 3, MFF UK, 2015
PDF
Lesson 11 Android Connect to the internet.pdf
PPTX
Android study jam iiitv kick-off sesson
PPTX
Android study jams 2021 [collab] [master]
PPTX
Week 1 - Android Study Jams
PPTX
Android Study Jams - Session 1
PPTX
Android Starting App Development
PDF
[PBO] Pertemuan 12 - Pemrograman Android
PPTX
Lesson 6 App navigation for beginners .pptx
PPTX
[EXTERNAL] Android Basics Sessions 1 _ 2 - Android Study Jams.pptx
PPTX
Unit 2 part for information technology1 4.pptx
Consistent UI Across Android Devices
Compose Camp 1.pdf
Android momobxl
Compose Camp 1.pdf
DSC ASEB Android Study Jams 2020: New to Programming 1
Android application development workshop day1
Week 5 slides
01.2 Layouts and resources for the UI.pptx
Introduction to Android Development with Java
Android Develpment vol. 3, MFF UK, 2015
Lesson 11 Android Connect to the internet.pdf
Android study jam iiitv kick-off sesson
Android study jams 2021 [collab] [master]
Week 1 - Android Study Jams
Android Study Jams - Session 1
Android Starting App Development
[PBO] Pertemuan 12 - Pemrograman Android
Lesson 6 App navigation for beginners .pptx
[EXTERNAL] Android Basics Sessions 1 _ 2 - Android Study Jams.pptx
Unit 2 part for information technology1 4.pptx
Ad

Recently uploaded (20)

PPTX
UNIT 4 Total Quality Management .pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Artificial Intelligence
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Well-logging-methods_new................
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
Digital Logic Computer Design lecture notes
PPT
Project quality management in manufacturing
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
composite construction of structures.pdf
PPTX
Current and future trends in Computer Vision.pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
UNIT 4 Total Quality Management .pptx
CYBER-CRIMES AND SECURITY A guide to understanding
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Artificial Intelligence
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Well-logging-methods_new................
CH1 Production IntroductoryConcepts.pptx
Sustainable Sites - Green Building Construction
Digital Logic Computer Design lecture notes
Project quality management in manufacturing
Internet of Things (IOT) - A guide to understanding
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
composite construction of structures.pdf
Current and future trends in Computer Vision.pptx
bas. eng. economics group 4 presentation 1.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
Ad

Lesson 13 App User Interface Design of movile app

  • 1. Apache 2 license This work is licensed under the Apache 2 license. Apache 2 license This work is licensed under the Apache 2 license. Android Development with Kotlin v1.0 1 Lesson 13: App UI design
  • 2. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. About this lesson Lesson 13: App UI design ● Android styling ● Typography ● Material Design ● Material Components ● Localization ● Example apps ● Summary 2
  • 3. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. 3 Android styling
  • 4. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Android styling system 4 ● Used to specify the visual design of your app ● Helps you maintain a consistent look across your app ● Hierarchical (you can inherit from parent styles and override specific attributes)
  • 5. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Precedence of each method of styling 5 View attributes Style Theme Overrides this Overrides this
  • 6. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Themes ● Collection of named resources, useful broadly across the app ● Named resources are known as theme attributes ● Examples: ○ Use a theme to define primary & secondary colors in the app ○ Use a theme to set the default font for all text within an activity 6
  • 7. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Declare a theme 7 <style name="Theme.MyApp" parent="Theme.MaterialComponents.Light"> <item name="colorPrimary">@color/orange_500</item> <item name="colorPrimaryVariant">@color/orange_700</item> <item name="colorSecondary">@color/pink_200</item> <item name="colorSecondaryVariant">@color/pink_700</item> ... </style> In res/values/themes.xml:
  • 8. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Apply a theme <manifest ... > <application ... > <activity android:theme="@style/Theme.MyApp" ... > </activity> </application> </manifest> 8 In AndroidManifest.xml: In layout file: <ConstraintLayout … android:theme="@style/Theme.MyApp">
  • 9. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Refer to theme attribute in a layout Use ?attr/themeAttributeName syntax. Examples: ?attr/colorPrimary ?attr/colorPrimaryVariant 9 <LinearLayout … android:background="?attr/colorSurface"> In layout file:
  • 10. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Styles ● A style is a collection of view attributes, specific to a type of view ● Use a style to create a collection of reusable styling information, such as font size or colors ● Good for declaring small sets of common designs used throughout your app 10
  • 11. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Declare a style 11 <style name="DescriptionStyle"> <item name="android:textColor">#00FF00</item> <item name="android:textSize">16sp</item> ... </style> In res/values/styles.xml:
  • 12. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Apply a style 12 <TextView style="@style/DescriptionStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/description_text" /> On a view in a layout file:
  • 13. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Refer to theme attribute in a style 13 <style name="DescriptionStyle"> <item name="android:textColor">?attr/colorOnSurface</item> <item name="android:textSize">16sp</item> ... </style> In res/values/styles.xml:
  • 14. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. View attributes ● Use view attributes to set attributes explicitly for each view ● You can use every property that can be set via styles or themes ● Use for custom or one-off designs such as margins, paddings, or constraints 14
  • 15. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Resources directory └── res ├── drawable ├── drawable-* ├── layout ├── menu ├── mipmap-* ├── navigation ├── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ ├── styles.xml │ └── themes.xml └── values-* 15
  • 16. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Provide alternative resources └── res ├── values │ ├── colors.xml │ ├── strings.xml │ ├── styles.xml │ └── themes.xml └── values-b+es │ ├── strings.xml └── values-night └── themes.xml 16 Use when device locale is set to Spanish Use when night mode is turned on
  • 17. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Color resources A way to name and standardize colors throughout your app 17 In res/values/colors.xml: <resources> <color name="purple_200">#FFBB86FC</color> <color name="purple_500">#FF6200EE</color> <color name="purple_700">#FF3700B3</color> <color name="teal_200">#FF03DAC5</color> <color name="teal_700">#FF018786</color> ... </resources> Specified as hexadecimal colors in form of #AARRGGBB
  • 18. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Dimension resources ● Declare your dimension values in res/values/dimens.xml: ● Refer to them as @dimen/<name> in layouts or R.dimen.<name> in code: 18 <resources> <dimen name="top_margin">16dp</dimen> </resources> <TextView … android:layout_marginTop="@dimen/top_margin" /> A way to name and standardize dimension values in your layouts
  • 19. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. 19 Typography
  • 20. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Scale-independent pixels (sp) ● The textual equivalent to density- independent pixels (dp) ● Specify text sizes in sp (takes into account user preferences) ● Users can adjust Font and Display sizes in the Settings app (after Display) 20
  • 21. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Type scale ● A set of styles designed to work together in a cohesive manner for your app and content ● Contains reusable categories of text with intended purpose for each (for example, headline, subtitle, caption) 21
  • 22. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. TextAppearance A TextAppearance style often alters one or more of these attributes: 22 ● typeface (android:fontFamily) ● weight (android:textStyle) ● text size (android:textSize) ● capitalization (android:textAllCaps) ● letter spacing (android:letterSpacing)
  • 23. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Examples using TextAppearance 23 <TextView ... android:textAppearance="@style/TextAppearance.MaterialComponents.Headline1" android:text="@string/title" /> <TextView ... android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" android:text="@string/body_text" />
  • 24. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Customize your own TextAppearance <style name="TextAppearance.MyApp.Headline1" parent="TextAppearance.MaterialComponents.Headline1"> ... <item name="android:textStyle">normal</item> <item name="android:textAllCaps">false</item> <item name="android:textSize">64sp</item> <item name="android:letterSpacing">0</item> ... </style> 24
  • 25. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Use a custom TextAppearance in a theme <style name="Theme.MyApp" parent="Theme.MaterialComponents.Light"> ... <item name="textAppearanceHeadline1">@style/TextAppearance.MyApp.Headline1</item> ... </style> 25
  • 26. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. 26 Material Design
  • 27. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Intro to Material Adaptable system of guidelines, components, and tools that support best practices for UI design Material Design homepage 27
  • 28. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Material Components Interactive building blocks for creating a user interface 28
  • 29. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Material color tool 29
  • 30. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Baseline Material color theme 30
  • 31. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Material Components for Android Library implementation 'com.google.android.material:material:<version>' 31
  • 32. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Material Themes 32 ● Theme.MaterialComponents ● Theme.MaterialComponents.NoActionBar ● Theme.MaterialComponents.Light ● Theme.MaterialComponents.Light.NoActionBar ● Theme.MaterialComponents.Light.DarkActionBar ● Theme.MaterialComponents.DayNight ● Theme.MaterialComponents.DayNight.NoActionBar ● Theme.MaterialComponents.DayNight.DarkActionBar
  • 33. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Material theme example 33 Theme.MaterialComponents.DayNight.DarkActionBar Light mode Dark mode
  • 34. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Dark theme A low-light UI that displays mostly dark surfaces ● Replaces light-tinted surfaces and dark text with dark-tinted surfaces and light text ● Makes it easier for anyone to use a device in lower-light environments ● Improves visibility for users with low vision and those sensitive to bright light ● Can significantly reduce power usage (depending on the device) 34
  • 35. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Support dark theme In values/themes.xml: 35 <style name="AppTheme" parent="Theme.MaterialComponents.DayNight"> <item name="colorPrimary">@color/orange_500</item> ... In values-night/themes.xml: <style name="AppTheme" parent="Theme.MaterialComponents.DayNight"> <item name="colorPrimary">@color/orange_200</item> ...
  • 36. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. 36 Material Components
  • 37. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Material Components Component library provided for Android and design guidelines 37 ● Text fields ● App bars (top and bottom) ● Buttons ● Floating Action Button (FAB) ● Menus ● Navigation Drawer ● Cards ● Bottom navigation ● Chips ● Snackbar ...and more!
  • 38. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Text field ● Composed of TextInputLayout with child view TextInputEditText ● Shows a floating label or a text hint before the user enters text ● Two types: 38 Filled text field Outlined text field
  • 39. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Text field example <com.google.android.material.textfield.TextInputLayout android:id="@+id/textField" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/label" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"> <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" /> </com.google.android.material.textfield.TextInputLayout> 39
  • 40. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Bottom navigation ● Allows movement between top level destinations in your app ● Alternate design pattern to a navigation drawer ● Limited to 5 locations max 40
  • 41. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Bottom navigation example 41 <LinearLayout …> ... <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_navigation" android:layout_width="match_parent" android:layout_height="wrap_content" app:menu="@menu/bottom_navigation_menu" /> </LinearLayout>
  • 42. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Bottom navigation listener bottomNav.setOnNavigationItemSelectedListener { item -> when(item.itemId) { R.id.item1 -> { // Respond to navigation item 1 click true } R.id.item2 -> { true } else -> false } } 42
  • 43. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Snackbar ● Display short messages within the app ● Messages have a duration (SHORT, LONG, or INDEFINITE) ● May contain an optional action ● Works best in a CoordinatorLayout ● Shown at bottom of enclosing container 43
  • 44. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Snackbar examples Show a simple message: Snackbar.make(view, R.string.text_label, Snackbar.LENGTH_SHORT) .show() 44 Add an action to a Snackbar: Snackbar.make(view, R.string.text_label, Snackbar.LENGTH_LONG) .setAction(R.string.action_text) { // Responds to click on the action } .show()
  • 45. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Floating Action Button (FAB) ● Perform the most-common action for a screen (for example, creating a new email) ● Come in multiple sizes (regular, mini, and extended) 45
  • 46. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. CoordinatorLayout ● Acts as top-level container in an app ● Manages interaction of its child views, such as gestures ● Recommended for use with views like a Snackbar or FAB 46
  • 47. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. FAB example <androidx.coordinatorlayout.widget.CoordinatorLayout ...> .... <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/floating_action_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="16dp" android:contentDescription="@string/fab_content_desc" app:fabSize="normal" <!-- or mini or auto --> app:srcCompat="@drawable/ic_plus"/> </androidx.coordinatorlayout.widget.CoordinatorLayout> 47
  • 48. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Cards ● A card holds content and actions for a single item. ● Cards are often arranged in a list, grid, or dashboard. ● Use MaterialCardView. 48
  • 49. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. MaterialCardView example <com.google.android.material.card.MaterialCardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp"> </com.google.android.material.card.MaterialCardView> 49 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <ImageView .../> <TextView .../> </LinearLayout>
  • 50. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. 50 Localization
  • 51. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Localize your app ● Separate the localized aspects of your app (for example, text, audio files, currency, and numbers) as much as possible from the core Kotlin functionality of the app. Example: Extract the user facing strings into strings.xml. ● When a user runs your app, the Android system selects which resources to load based on the device's locale. ● If locale-specific resources are not found, Android falls back to default resources you defined. 51
  • 52. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Support different languages and cultures ● Decide which locales to support. ● Create locale-specific directories in res directory: <resource type>-b+<language code> [+<country code>] Examples: layout-b+en+US values-b+es ● Provide locale-specific resources (such as strings and drawables) in those directories. 52
  • 53. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Support languages that use RTL scripts 53 ● Users can choose a language that uses right-to-left (RTL) scripts. ● Add android:supportsRtl="true" to app tag in manifest. ● Convert left and right to start and end, respectively, in your layout files (change android:paddingLeft to android:paddingStart). ● Localize strings and format text in messages. ● Optionally, use -ldrtl resource qualifier to provide alternate resources.
  • 54. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. 54 Example apps
  • 55. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Check out other apps 55 Sunflower app Google I/O app
  • 56. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. 56 Summary
  • 57. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Summary In Lesson 13, you learned how to: ● Customize the visual look of your app using styles and themes ● Choose from predefined type scales for the text in your app (or create your own text appearance) ● Select theme colors for your app using Material color tool ● Use Material Components library to speed up UI development ● Localize your app to support different languages and cultures 57
  • 58. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Learn more 58 ● Material Design ● Material Components ● Tools for picking colors ● Dark theme ● Localize your app ● Blog posts: Themes vs Styles, Common Theme Attributes, Prefer Theme Attributes, Themes Overlay ● Sample code: Sunflower app, Google I/O app, Android GitHub repo
  • 59. Android Development with Kotlin Apache 2 license This work is licensed under the Apache 2 license. Pathway 59 Practice what you’ve learned by completing the pathway: Lesson 13: App UI Design