Reputation: 1
I'm new to Android development and learning about the jetpack compose and kotlin. In my learning process I'm trying to build a timer app. I don't know how use an existing chronometer library with jetpack compose and kotlin.
I found android.widget.Chronometer but is it only for xml or can it be used with jetpack compose? If yes then how?
Upvotes: 0
Views: 619
Reputation: 4266
Yes, you can use Views in Compose - Using Views in Compose. For example:
@Composable
fun MyTimer() {
Column {
var chronometer: Chronometer? = null
TextButton(onClick = { chronometer?.start() }) {
Text("Start")
}
TextButton(onClick = { chronometer?.stop() }) {
Text("Stop")
}
AndroidView(
factory = { context ->
Chronometer(context).also { chronometer = it }
},
)
}
}
Upvotes: 0