openharmony 鸿蒙 ts-universal-accessibility-hover-event

2025-06-12 浏览 (1)

Accessibility Hover Event

When accessibility mode is enabled, touch events are converted into accessibility hover events.

NOTE

  • The initial APIs of this module are supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version.
  • Currently, conversion into accessibility hover events can only be initiated by enabling accessibility mode.

onAccessibilityHover

onAccessibilityHover(callback: AccessibilityCallback): T

Invoked in accessibility mode when a single finger touches the bound component.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
callbackAccessibilityCallbackYesCallback invoked in accessibility mode when a single finger touches the bound component.

Return value

TypeDescription
TCurrent component.

AccessibilityCallback

type AccessibilityCallback = (isHover: boolean, event: AccessibilityHoverEvent) => void

Represents the accessibility hover event callback, which is effective when accessibility mode is enabled.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
isHoverbooleanYesWhether a finger is hovering over the component in accessibility mode. The accessibility hover event is converted from a touch event, with the value true when the finger enters the component and false when it exits.
eventAccessibilityHoverEventYesAccessibilityHoverEvent object.

AccessibilityHoverEvent

Inherits from BaseEvent.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeDescription
typeAccessibilityHoverTypeAccessibility hover type.
xnumberX coordinate of the finger's position relative to the upper left corner of the component being touched.
Unit: vp
ynumberY coordinate of the finger's position relative to the upper left corner of the component being touched.
Unit: vp
windowXnumberX coordinate of the finger's position relative to the upper left corner of the application window.
Unit: vp
windowYnumberY coordinate of the finger's position relative to the upper left corner of the application window.
Unit: vp
displayXnumberX coordinate of the finger's position relative to the upper left corner of the display.
Unit: vp
displayYnumberY coordinate of the finger's position relative to the upper left corner of the display.
Unit: vp

AccessibilityHoverType

Enumerates the accessibility hover types.

NameValueDescription
HOVER_ENTER0A finger is pressed.
HOVER_MOVE1The touch moves.
HOVER_EXIT2The finger is lifted.
HOVER_CANCEL3The current event is canceled.

Example

This example demonstrates how to use the onAccessibilityHover event to customize a button in accessibility mode.

// xxx.ets
@Entry
@Component
struct OnAccessibilityHoverEventExample {
  @State hoverText: string = 'no hover';
  @State color: Color = Color.Blue;

  build() {
    Column({ space: 20 }) {
      Button(this.hoverText)
        .width(180).height(80)
        .backgroundColor(this.color)
        .onAccessibilityHover((isHover: boolean, event: AccessibilityHoverEvent) => {
          // Use the onAccessibilityHover event to dynamically change the text content and background color of a button when the finger is hovered on it.
          if (isHover) {
            this.hoverText = 'hover';
            this.color = Color.Pink;
          } else {
            this.hoverText = 'no hover';
            this.color = Color.Blue;
          }
        })
    }.padding({ top: 30 }).width('100%')
  }
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArcButton

harmony 鸿蒙ArcSlider

harmony 鸿蒙Chip

harmony 鸿蒙ChipGroup

harmony 鸿蒙ComposeListItem

harmony 鸿蒙ComposeTitleBar

harmony 鸿蒙advanced.Counter

harmony 鸿蒙Dialog Box (Dialog)

harmony 鸿蒙DialogV2

harmony 鸿蒙DownloadFileButton

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/6LZMiq