Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
Composing Your First UI
With your framework views out of the way, you are ready to write your first Compose UI. The default layout in the Empty Activity project template you have used throughout this book includes an empty Activity with the text “Hello World!” For your first Compose UI, you will remake this layout without any framework views. (Printing “Hello World!” to the screen is a time-honored coding tradition.)
To populate an activity with a Compose UI, you use a function called setContent. This function accepts a lambda expression, which is where you have access to Compose UI elements, called composables. Use the Text composable to show the text “Hello World!”
Listing 26.4 Writing a Compose UI (MainActivity.kt)
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