-
Notifications
You must be signed in to change notification settings - Fork 0
Lab 19
Nate Ebel edited this page Jul 22, 2022
·
4 revisions
Start building out a simple Jetpack Compose application to list and display locations.
-
Open the
Compose Locations
project in Android Studio -
Deploy the new project
-
Create a
MainScreen()
composable function that displays a list of cards- The
MainScreen
function should use aScaffold()
as it's first child composable - The
Scaffold
should define atopBar
using theSmallTopAppBar()
composable - The
SmallTopAppBar()
should have a title of"Compose Location"s
- The
content
lambda of theScaffold
should contain aLazyColumn()
- The
LazyColumn
should display a list ofCard()
- Each
Card
should represent a "location" and include a titleText()
composable with value"Location $index"
- The
-
Create a composable preview that displays
MainContent
- Create a new function named
Preview
- Annotate it with
@Composable
- Annotate it with
@Preview
- Create a new function named
-
Create a
MapScreen
composable that displays a selected location- The
MapScreen
composable should take a parameterindex: Int
and a parameteronBackClick: () -> Unit
- It should include a
Scaffold
- The
Scaffold
should have atopBar
usingSmallTopAppBar
- The
SmallTopAppBar
should define a back button usingnavigationIcon
andIconButton
- Clicking the back icon should call the
onBackClick
function
- The
-
Create a variable controlling whether the
MainContent
orMapContent
composable is being shown- This can be done using
remember{}
andmutableStateOf()
like thisvar selectedIndex: Int? by remember { mutableStateOf(null) }
- If
selectedIndex
is null, showMainScreen
- If
selectedIndex
is not null, showMapScreen
- This can be done using
- Update the color schems in
Theme.kt
to customize the theme of your application - Update the text styles in
Type.kt
to customize the typography in your application
var selectedIndex: Int? by remember { mutableStateOf(null) }
if (selectedIndex == null) {
MainScreen() { index ->
selectedIndex = index
}
} else {
MapScreen(index = selectedIndex!!) {
selectedIndex = null
}
}