Java implementation for TimeText component in Wear OS development

I need to add a clock display at the top section of my Wear OS app. This seems like standard practice and I heard Google might require it for Play Store submissions based on recent developer events.

The issue is that Google’s documentation only shows Kotlin examples for their TimeText component. This component is supposed to be the recommended way to show time and automatically adjusts for different watch screen shapes (round vs square).

I know I could create a custom solution using setText() with a timer or runnable, but that approach won’t follow Google’s design guidelines and won’t handle different screen types properly.

What’s the correct way to implement TimeText using Java instead of Kotlin? I checked the XML layout options but couldn’t find TimeText listed there either.

TimeText needs Compose integration even in Java projects. What got me at first was the theme setup - you have to wrap TimeText with WearMaterialTheme in your ComposeView’s setContent block or the styling looks terrible. Also heads up - older Wear OS versions break some TimeText features. I’d test on both round and square emulators early since the component acts differently on each. The curve handling works great once it’s set up right, but Java projects need way more boilerplate than straight Kotlin Compose.

Yes, you can use TimeText in Java, even though most examples are in Kotlin. You’ll need Google’s Horologist library for the TimeText functionality. Just create it programmatically in your activity or fragment and add it to your layout. Import com.google.android.horologist.compose.material.TimeText and set it up through ComposeView if you’re mixing Compose with regular Android Views. I hit this same documentation issue when migrating an old Java watch face project. XML won’t work since TimeText is a Compose component, not a traditional View. Create a ComposeView container in your XML, then populate it with TimeText in your Java code. Don’t forget the Horologist dependencies in build.gradle. Once it’s configured, the component handles curved text positioning automatically - saves tons of time vs building it yourself.

had this same issue last month. use androidx.wear.compose.material.TimeText with ComposeView in your java activity. just import the wear compose dependencies and wrap it in a ComposeView container. way simpler than i expected - it’s compose-based, not traditional views.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.