Creating your first button
In this recipe, we will create our first button in Wear OS to explore the principles and best practices of building in Wear OS.
Getting ready
You need to have completed the previous recipe to get started on this one. We will be building upon our already created WearOSExample
project.
How to do it…
To create your first button on Wear OS in Jetpack Compose, you can follow these steps:
- Using the already-created project, we will be adding a new button. Let’s go ahead and remove some of the already provided code,
fun
Greeting(greetingName: String)
:
Figure 10.7 – A screenshot showing what to be deleted
- Removing the
Greeting()
function called inWearOSExampleTheme
will complain; go ahead and remove that too. - Then create a new
Composable
function that will define your button. You can use theButton
function provided by Jetpack Compose:@Composable
fun SampleButton() {
...