1
Lesson 13:
App UI design
This work is licensed under the Apache 2 license.
Android Development with Kotlin v1.0
This work is licensed under the Apache 2 license.
About this lesson
Lesson 13: App UI design
2
Android Development with Kotlin
This work is licensed under the Apache 2 license.
3
Android styling
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Android styling system
4
Android Development with Kotlin
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
This work is licensed under the Apache 2 license.
Themes
6
Android Development with Kotlin
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
This work is licensed under the Apache 2 license.
Apply a theme
<manifest ... >
<application ... >
<activity android:theme="@style/Theme.MyApp" ... >
</activity>
</application>
</manifest>
<ConstraintLayout â¦
android:theme="@style/Theme.MyApp">
8
In AndroidManifest.xml:
In layout file:
Android Development with Kotlin
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
<LinearLayout â¦
android:background="?attr/colorSurface">
9
In layout file:
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Styles
10
Android Development with Kotlin
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
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
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
This work is licensed under the Apache 2 license.
View attributes
14
Android Development with Kotlin
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
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
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
This work is licensed under the Apache 2 license.
Dimension resources
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
This work is licensed under the Apache 2 license.
19
Typography
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Scale-independent pixels (sp)
20
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Type scale
21
Android Development with Kotlin
This work is licensed under the Apache 2 license.
TextAppearance
A TextAppearance style often alters one or more of these attributes:
22
Android Development with Kotlin
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
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
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
This work is licensed under the Apache 2 license.
26
Material Design
Android Development with Kotlin
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
27
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Material Components
Interactive building blocks for creating a user interface
28
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Material color tool
29
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Baseline Material color theme
30
Android Development with Kotlin
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
This work is licensed under the Apache 2 license.
Material Themes
32
Android Development with Kotlin
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
This work is licensed under the Apache 2 license.
Dark theme
A low-light UI that displays mostly dark surfaces
34
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Support dark theme
In values/themes.xml:
In values-night/themes.xml:
35
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">@color/orange_500</item>
...
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">@color/orange_200</item>
...
Android Development with Kotlin
This work is licensed under the Apache 2 license.
36
Material Components
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Material Components
Component library provided for Android and design guidelines
37
|
|
|
|
|
|
|
|
|
|
...and more!
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Text field
38
Filled text field
Outlined text field
Android Development with Kotlin
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
This work is licensed under the Apache 2 license.
Bottom navigation
40
Android Development with Kotlin
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
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
This work is licensed under the Apache 2 license.
Snackbar
43
Android Development with Kotlin
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
This work is licensed under the Apache 2 license.
Floating Action Button (FAB)
45
Android Development with Kotlin
This work is licensed under the Apache 2 license.
CoordinatorLayout
46
Android Development with Kotlin
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
This work is licensed under the Apache 2 license.
Cards
48
Android Development with Kotlin
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
This work is licensed under the Apache 2 license.
50
Localization
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Localize your app
Example: Extract the user facing strings into strings.xml.
51
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Support different languages and cultures
<resource type>-b+<language code>� [+<country code>]
Examples: layout-b+en+US� values-b+es
52
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Support languages that use RTL scripts
53
Android Development with Kotlin
This work is licensed under the Apache 2 license.
54
Example apps
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Check out other apps
55
Sunflower app
Google I/O app
Android Development with Kotlin
This work is licensed under the Apache 2 license.
56
Summary
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Summary
In Lesson 13, you learned how to:
57
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Learn more
58
Android Development with Kotlin
This work is licensed under the Apache 2 license.
Pathway
Practice what youâve learned by�completing the pathway:
59
Android Development with Kotlin
This work is licensed under the Apache 2 license.