I want to be able to change the image on a button later in my program - not during creation.
My main class
class MainActivity : ComponentActivity() {
lateinit var button: Unit
...
setContent {
button = WearApp()
}
WearApp is composable
@Composable
fun WearApp() {
var _button: Unit = println("Fake Empty Initialization")
MosaicTheme {
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Transparent),
contentAlignment = Alignment.Center
) {
_button = Button(
onClick = {
...
}
return _button
So back in MainActivity I have a variable button: Unit. How do I work with that as a Button? How do I change the image on the button?
I assume that you want to change an image when you need it to update.
If that the case, you need you have a state of icon to store it and use in button.
Here is example.
I only test with the click function. Please take this as an example.