Jetpack Compose: Getting Started

Aug 1 2023 · Kotlin 1.8.10, Android 13, Android Studio Flamingo

Part 2: Layout Your App

09. Organize Your Code

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 08. Add Spacers Next episode: 10. Challenge: Add a TextField

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Thus far, we have been writing our code in different files contained within different packages.

Error: This image is missing a width attribute

Please provide one in the form of ![width=50%](https://user-images.githubusercontent.com/23483887/135744985-0b0b8b0a-5b0a-4b0a-8b0a-9b0a0b0a0b0a.png)

Bottom Navigation Bar

Let us create a new component that will be used to display the bottom navigation bar in our app.

@Composable
fun BottomBarItem(
    modifier: Modifier = Modifier,
    title: String,
) {
  Text(
      text = title,
      modifier = modifier,
      fontStyle = FontStyle.Italic,
      fontSize = 10.sp)
}
@Composable
fun BottomNavBar() {
  Box(modifier = Modifier
      .padding(8.dp)
      .fillMaxWidth()){

    Row(modifier = Modifier
        .fillMaxWidth()
        .height(56.dp),
        horizontalArrangement = Arrangement.SpaceEvenly,
        verticalAlignment = Alignment.CenterVertically) {

      BottomBarItem(title = "Home")

      BottomBarItem(title = "Search")

      BottomBarItem(title = "Profile")

    }

  }
}

Food Detail Screen

Let us create a new file inside the screens package called FoodDetailScreen.kt. This file will contain the FoodDetailScreen Composable.

@Composable
fun FoodDetails(
    foodId: Int? = 0
) {
    val food = getFood()[ foodId ?: 0]

    Box(
        modifier = Modifier
            .fillMaxSize()
            .background(color = Color.White)
    ){

        Box(
            modifier = Modifier
                .fillMaxWidth()
                .height(300.dp)
                .paint(
                    painter = painterResource(id = food.banner),
                    contentScale = ContentScale.FillBounds
                )
        )

    }

}

Theme

The theme package, found within ui, contains files that will be used to store the theme of our app.