Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Jetpack Compose How to show tooltip after simple click

I saw a an answer on how to implement the new tooltipBox (Android Compose - Alternative to PlainTooltipBox (deprecated))

But now it only works after a LongPress on my Icon, how can I change this. is it possible to show after one click and dismiss after clicking again or somewhere else ?

So far this is my Code:

TooltipBox(
                        positionProvider = TooltipDefaults.rememberRichTooltipPositionProvider(),
                        tooltip = { RichTooltip(title = { Text("Smart Cycle") }, text = { Text("If enabled, the cycle will automatically be detected, starting with the highest paycheck") })},
                        state = rememberTooltipState()) {
                            IconButton(onClick = {  }) {
                                Icon(Icons.Default.Info, contentDescription = "info")
                            }
                    }

I thought maybe its possible to change that in the state

like image 746
Luca Christ Avatar asked Oct 16 '25 04:10

Luca Christ


1 Answers

You can manually show the tooltip by calling TooltipState::show as you can see in RichTooltipWithManualInvocationSample:

val tooltipState = rememberTooltipState()
val scope = rememberCoroutineScope()

TooltipBox(
    state = tooltipState,
    ...
) {
    IconButton(
        onClick = { scope.launch { tooltipState.show() } }
    ) { ... }
}
like image 61
Jan Bína Avatar answered Oct 17 '25 18:10

Jan Bína



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!