Skip to content

Instantly share code, notes, and snippets.

@tdcolvin
Created February 6, 2024 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdcolvin/16f15b1e93a097374a2e0ef5feb9643d to your computer and use it in GitHub Desktop.
Save tdcolvin/16f15b1e93a097374a2e0ef5feb9643d to your computer and use it in GitHub Desktop.
@Composable
fun RandomColourButton() {
val scope = rememberCoroutineScope()
var buttonColor by remember { mutableStateOf(Color.Red) }
Column {
Button(colors = ButtonDefaults.buttonColors(backgroundColor = buttonColor),
onClick = {
scope.launch {
while(true) {
delay(500)
buttonColor = Color(Random.nextInt(0xFF), Random.nextInt(0xFF), Random.nextInt(0xFF), 0xFF)
}
}
}
) {
Text("Cycle Random Colours")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment