Jetpack Compose

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

Part 1: Jetpack Compose Basics

03. Use Basic Compose Building Blocks

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: 02. Learn About Composable Functions Next episode: 04. Add State to Composables

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.

Notes: 03. Use Basic Compose Building Blocks

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’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

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))
    }
  }
}