{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

IndicationKt

public final class IndicationKt


Summary

Public methods

static final @NonNull ProvidableCompositionLocal<@NonNull Indication>

CompositionLocal that provides an Indication through the hierarchy.

static final @NonNull Modifier
indication(
    @NonNull Modifier receiver,
    @NonNull InteractionSource interactionSource,
    Indication indication
)

Draws visual effects for this component when interactions occur.

Public methods

getLocalIndication

public static final @NonNull ProvidableCompositionLocal<@NonNull IndicationgetLocalIndication()

CompositionLocal that provides an Indication through the hierarchy. This Indication will be used by default to draw visual effects for interactions such as press and drag in components such as clickable.

By default this will provide DefaultDebugIndication.

indication

public static final @NonNull Modifier indication(
    @NonNull Modifier receiver,
    @NonNull InteractionSource interactionSource,
    Indication indication
)

Draws visual effects for this component when interactions occur.

import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.clickable
import androidx.compose.foundation.indication
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredHeight
import androidx.compose.material.Text
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

val interactionSource = remember { MutableInteractionSource() }
Column {
    Text(
        text = "Click me and my neighbour will indicate as well!",
        modifier = Modifier
            // clickable will dispatch events using MutableInteractionSource and show ripple
            .clickable(
                interactionSource = interactionSource,
                indication = rememberRipple()
            ) {
                /**do something */
            }
            .padding(10.dp)
    )
    Spacer(Modifier.requiredHeight(10.dp))
    Text(
        text = "I'm neighbour and I indicate when you click the other one",
        modifier = Modifier
            // this element doesn't have a click, but will show default indication from the
            // CompositionLocal as it accepts the same MutableInteractionSource
            .indication(interactionSource, LocalIndication.current)
            .padding(10.dp)
    )
}
Parameters
@NonNull InteractionSource interactionSource

InteractionSource that will be used by indication to draw visual effects - this InteractionSource represents the stream of Interactions for this component.

Indication indication

Indication used to draw visual effects. If null, no visual effects will be shown for this component.