Jetpack Compose

Oct 11 2022 Kotlin 1.7.10, Android 13, Android Studio Chipmunk

Part 1: Jetpack Compose Basics

3. Use Basic Compose Building Blocks

Episode complete

Play next episode

Next
Save for later
About this episode
See versions

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 2. Learn About Composable Functions Next episode: 4. Add State to Composables

The student materials have been reviewed and are updated as of September 2022.

In ui/addBook/AddBookActivity, within AddBookTopBar() composable function, the method onBackPressed() is deprecated and is replaced by onBackPressedDispatcher.onBackPressed() method.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

Demo

Now that you’ve learned a bit about basic composable functions and how they work, you’re ready to dive deeper and learn about more composables and how to combine them together.

override fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)
  setContent { AddBookContent() } // here
}

@Composable
fun AddBookContent() {
  Scaffold(topBar = { AddBookTopBar() }) {
    AddBookFormContent()
  }
}
@Composable
fun AddBookTopBar() {
  TopAppBar(
    title = {
      Text(text = stringResource(id = R.string.add_book_title))
    },
    navigationIcon = {
      IconButton(onClick = { onBackPressedDispatcher.onBackPressed() }) {
        Icon(Icons.Default.ArrowBack, contentDescription = "Back")
      }
    },
    contentColor = Color.White,
    backgroundColor = colorResource(id = R.color.colorPrimary)
  )
}
@Composable
fun AddBookFormContent() {
  Column(
    modifier = Modifier.fillMaxSize(),
    horizontalAlignment = Alignment.CenterHorizontally
  ) {
  
  }
}
@Composable
fun AddBookFormContent() {
  Column(
    modifier = Modifier.fillMaxSize(),
    horizontalAlignment = Alignment.CenterHorizontally
  ) {
    OutlinedTextField(
      value = "",
      onValueChange = {},
      label = { Text(text = stringResource(id = R.string.book_title_hint)) })

    OutlinedTextField(
      value = "",
      onValueChange = {},
      label = { Text(text = stringResource(id = R.string.book_description_hint)) })
  }
}
@Composable
fun AddBookFormContent() {
  Column(
    modifier = Modifier.fillMaxSize(),
    horizontalAlignment = Alignment.CenterHorizontally
  ) {
	...
      Row {
        TextButton(
          onClick = {},
          content = { Text(text = stringResource(id = R.string.genre_select)) })

        DropdownMenu(
          expanded = false,
          onDismissRequest = {}) {

          DropdownMenuItem(onClick = {}) {

          }
        }
      }
  }
}
@Composable
fun AddBookFormContent() {
  Column(
    modifier = Modifier.fillMaxSize(),
    horizontalAlignment = Alignment.CenterHorizontally
  ) {
	...
    TextButton(
      onClick = { onAddBookTapped() }
    ) {
      Text(text = stringResource(id = R.string.add_book_button_text))
    }
  }
}