Unlock the potential of these advanced techniques to elevate your smartwatch app design and functionality to new heights.

If you’re developing an application for WearOs you’ve surely come across the Scaffold showing the TimeText():

WearOs Time in scaffold

Well, then in that case the guide is made just for you! and is made in Jetpack Compose!

What you will archive today

To achieve the effect you see above, thus being able to create your custom curved text at the position of your choice, in Jetpack Compose, you can take advantage of the CurvedLayout with the curvedText.

1. As first make sure you have the dependencies in your module:


2. Then, create the composable function that allows you to write the text :

private fun MyCoolCurvedText(anchor: Float, color: Color, text: String) {
anchor = anchor,
anchorType = AnchorType.Center,
modifier = Modifier.fillMaxSize(),
) {
) {
text = text,
style = CurvedTextStyle(
fontSize = 14.sp,
color = color

//required imports:
//import androidx.wear.compose.foundation.AnchorType
//import androidx.wear.compose.foundation.CurvedLayout
//import androidx.wear.compose.foundation.CurvedTextStyle
//import androidx.wear.compose.foundation.curvedRow
//import androidx.wear.compose.material.curvedText

Of course, you can customize it to your liking, and put in more items according to your needs

3. Use it inside your UI

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
setContent {
Box(Modifier.fillMaxSize()) {
anchor = 0f,
color = Color.Red,
text = "Rounded text!"
anchor = 90f,
color = Color.Green,
text = "WearOs today!"
anchor = 180f,
color = Color.Blue,
text = "I'm rounded!"
anchor = 270f,
color = Color.Yellow,
text = "Hello devs!"

And there you have it!

If you are interested in more WearOs Jetpack Compose Android tips let me know in the comments!

Source link