Chapter 18. Jetpack Compose: Compose Yourself

image

All the UIs you’ve built so far have used views and layout files.

But with Jetpack Compose, that’s not the only option. In this chapter, we’re going to take a road trip to Composeville, and find out how to build UIs using Compose components called composables instead of views. You’ll learn how to use built-in composables such as Text, Image, TextField, and Button. You’ll discover how to arrange them in Rows and Columns, and style them using themes. You’ll write and preview your own composable functions. You’ll even find out how to manage a composable’s state using MutableState objects. Turn the page, and let’s get composing…

UI components don’t have to be Views

So far in this book, you’ve learned how to use layout files and views to build swish, interactive UIs. But while we’ve focused on this approach, it’s not your only option.

An alternative is to build your UI using Jetpack Compose. Compose is part of Android Jetpack; it’s an entire toolkit of libraries, tools, and APIs designed to help you build native UIs with pure Kotlin code.

The great news is that using Jetpack Compose builds on your existing Android knowledge. You can use view models and live data with Compose, for example, and even add Compose components to existing UIs.

Note

You’ll find out more about this in the next chapter.

We’re ...

Get Head First Android Development, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.