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

ClickableKt

public final class ClickableKt


Summary

Public methods

static final @NonNull Modifier
clickable(
    @NonNull Modifier receiver,
    boolean enabled,
    String onClickLabel,
    Role role,
    @NonNull Function0<Unit> onClick
)

Configure component to receive clicks via input or accessibility "click" event.

static final @NonNull Modifier
clickable(
    @NonNull Modifier receiver,
    @NonNull MutableInteractionSource interactionSource,
    Indication indication,
    boolean enabled,
    String onClickLabel,
    Role role,
    @NonNull Function0<Unit> onClick
)

Configure component to receive clicks via input or accessibility "click" event.

static final @NonNull Modifier
@ExperimentalFoundationApi
combinedClickable(
    @NonNull Modifier receiver,
    boolean enabled,
    String onClickLabel,
    Role role,
    String onLongClickLabel,
    Function0<Unit> onLongClick,
    Function0<Unit> onDoubleClick,
    @NonNull Function0<Unit> onClick
)

Configure component to receive clicks, double clicks and long clicks via input or accessibility "click" event.

static final @NonNull Modifier
@ExperimentalFoundationApi
combinedClickable(
    @NonNull Modifier receiver,
    @NonNull MutableInteractionSource interactionSource,
    Indication indication,
    boolean enabled,
    String onClickLabel,
    Role role,
    String onLongClickLabel,
    Function0<Unit> onLongClick,
    Function0<Unit> onDoubleClick,
    @NonNull Function0<Unit> onClick
)

Configure component to receive clicks, double clicks and long clicks via input or accessibility "click" event.

Public methods

clickable

public static final @NonNull Modifier clickable(
    @NonNull Modifier receiver,
    boolean enabled,
    String onClickLabel,
    Role role,
    @NonNull Function0<Unit> onClick
)

Configure component to receive clicks via input or accessibility "click" event.

Add this modifier to the element to make it clickable within its bounds and show a default indication when it's pressed.

This version has no MutableInteractionSource or Indication parameters, default indication from LocalIndication will be used. To specify MutableInteractionSource or Indication, use another overload.

If you need to support double click or long click alongside the single click, consider using combinedClickable.

import androidx.compose.foundation.clickable
import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier

val count = remember { mutableStateOf(0) }
// content that you want to make clickable
Text(text = count.value.toString(), modifier = Modifier.clickable { count.value += 1 })
Parameters
boolean enabled

Controls the enabled state. When false, onClick, and this modifier will appear disabled for accessibility services

String onClickLabel

semantic / accessibility label for the onClick action

Role role

the type of user interface element. Accessibility services might use this to describe the element or do customizations

@NonNull Function0<Unit> onClick

will be called when user clicks on the element

clickable

public static final @NonNull Modifier clickable(
    @NonNull Modifier receiver,
    @NonNull MutableInteractionSource interactionSource,
    Indication indication,
    boolean enabled,
    String onClickLabel,
    Role role,
    @NonNull Function0<Unit> onClick
)

Configure component to receive clicks via input or accessibility "click" event.

Add this modifier to the element to make it clickable within its bounds and show an indication as specified in indication parameter.

If you need to support double click or long click alongside the single click, consider using combinedClickable.

import androidx.compose.foundation.clickable
import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier

val count = remember { mutableStateOf(0) }
// content that you want to make clickable
Text(text = count.value.toString(), modifier = Modifier.clickable { count.value += 1 })
Parameters
@NonNull MutableInteractionSource interactionSource

MutableInteractionSource that will be used to dispatch PressInteraction.Press when this clickable is pressed. Only the initial (first) press will be recorded and dispatched with MutableInteractionSource.

Indication indication

indication to be shown when modified element is pressed. By default, indication from LocalIndication will be used. Pass null to show no indication, or current value from LocalIndication to show theme default

boolean enabled

Controls the enabled state. When false, onClick, and this modifier will appear disabled for accessibility services

String onClickLabel

semantic / accessibility label for the onClick action

Role role

the type of user interface element. Accessibility services might use this to describe the element or do customizations

@NonNull Function0<Unit> onClick

will be called when user clicks on the element

combinedClickable

@ExperimentalFoundationApi
public static final @NonNull Modifier combinedClickable(
    @NonNull Modifier receiver,
    boolean enabled,
    String onClickLabel,
    Role role,
    String onLongClickLabel,
    Function0<Unit> onLongClick,
    Function0<Unit> onDoubleClick,
    @NonNull Function0<Unit> onClick
)

Configure component to receive clicks, double clicks and long clicks via input or accessibility "click" event.

Add this modifier to the element to make it clickable within its bounds.

If you need only click handling, and no double or long clicks, consider using clickable

This version has no MutableInteractionSource or Indication parameters, default indication from LocalIndication will be used. To specify MutableInteractionSource or Indication, use another overload.

import androidx.compose.foundation.clickable
import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier

val count = remember { mutableStateOf(0) }
// content that you want to make clickable
Text(text = count.value.toString(), modifier = Modifier.clickable { count.value += 1 })
Parameters
boolean enabled

Controls the enabled state. When false, onClick, onLongClick or onDoubleClick won't be invoked

String onClickLabel

semantic / accessibility label for the onClick action

Role role

the type of user interface element. Accessibility services might use this to describe the element or do customizations

String onLongClickLabel

semantic / accessibility label for the onLongClick action

Function0<Unit> onLongClick

will be called when user long presses on the element

Function0<Unit> onDoubleClick

will be called when user double clicks on the element

@NonNull Function0<Unit> onClick

will be called when user clicks on the element

combinedClickable

@ExperimentalFoundationApi
public static final @NonNull Modifier combinedClickable(
    @NonNull Modifier receiver,
    @NonNull MutableInteractionSource interactionSource,
    Indication indication,
    boolean enabled,
    String onClickLabel,
    Role role,
    String onLongClickLabel,
    Function0<Unit> onLongClick,
    Function0<Unit> onDoubleClick,
    @NonNull Function0<Unit> onClick
)

Configure component to receive clicks, double clicks and long clicks via input or accessibility "click" event.

Add this modifier to the element to make it clickable within its bounds.

If you need only click handling, and no double or long clicks, consider using clickable.

Add this modifier to the element to make it clickable within its bounds.

import androidx.compose.foundation.clickable
import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier

val count = remember { mutableStateOf(0) }
// content that you want to make clickable
Text(text = count.value.toString(), modifier = Modifier.clickable { count.value += 1 })
Parameters
@NonNull MutableInteractionSource interactionSource

MutableInteractionSource that will be used to emit PressInteraction.Press when this clickable is pressed. Only the initial (first) press will be recorded and emitted with MutableInteractionSource.

Indication indication

indication to be shown when modified element is pressed. By default, indication from LocalIndication will be used. Pass null to show no indication, or current value from LocalIndication to show theme default

boolean enabled

Controls the enabled state. When false, onClick, onLongClick or onDoubleClick won't be invoked

String onClickLabel

semantic / accessibility label for the onClick action

Role role

the type of user interface element. Accessibility services might use this to describe the element or do customizations

String onLongClickLabel

semantic / accessibility label for the onLongClick action

Function0<Unit> onLongClick

will be called when user long presses on the element

Function0<Unit> onDoubleClick

will be called when user double clicks on the element

@NonNull Function0<Unit> onClick

will be called when user clicks on the element