Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
Previewing Composables
If you are a fan of Android Studio’s design view for XML layouts, you may be wondering if you can preview your Compose layouts the same way.
Preview functionality is available for Compose, but Android Studio needs a little help:
You must opt in to previews for each composable.
Do this now for your ToppingCell composable by annotating it with the @Preview annotation.
Listing 26.9 Enabling previews on a composable (ToppingCell.kt)
@Preview
@Composable
fun ToppingCell() {
...
}
Android Studio uses your project’s compiled code to generate previews of composables. This means that your project must be built to show changes you have made in the preview. Build your project now by pressing the Build icon ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access