How do you make a text clickable in jetpack compose ? I would also like to toggle it to non clickable after selecting once

This is my code:

    text = "Resend OTP",
    fontSize = 20.sp,
    color =  Textfieldcolor,
    style = TextStyle(textDecoration = TextDecoration.Underline)

I want the text to be clickable once and then disabled.

How do I do this?


  • You can add the clickable modifier to your Text or use ClickableText instead of Text.

    Here is an example of how to do it with ClickableText:

    var enabled by remember { mutableStateOf(true)}
        text = AnnotatedString(text) ,
        onClick = {
            if (enabled) {
                enabled = false
                text = "Disabled"