Click control attributes are used to set whether a component can respond to finger interactions such as click and touch events.
The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
touchable(value: boolean): T
Whether the component can respond to finger interactions such as click and touch events.
This API is supported since API version 7 and deprecated since API version 9. You are advised to use hitTestBehavior instead.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | boolean | Yes | Whether the component can respond to finger interactions such as click and touch events. true (default): The component can respond to finger interactions. false: The component cannot respond to finger interactions. |
Return value
| Type | Description |
|---|---|
| T | Current component. |
// xxx.ets
@Entry
@Component
struct TouchAbleExample {
@State text1: string = ''
@State text2: string = ''
build() {
Stack() {
Rect()
.fill(Color.Gray).width(150).height(150)
.onClick(() => {
console.info(this.text1 = 'Rect Clicked')
})
.overlay(this.text1, { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
Ellipse()
.fill(Color.Pink).width(150).height(80)
.touchable(false) // When the Ellipse area is touched, the message "Ellipse Clicked" is not displayed.
.onClick(() => {
console.info(this.text2 = 'Ellipse Clicked')
})
.overlay(this.text2, { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
}.margin(100)
}
} 