鼠标滑动,或者手写笔在屏幕上悬浮移动扫过组件时触发。onHoveronHover(event: (isHover: boolean, event: HoverEvent) => void): T鼠标或手写笔进入或退出组件时触发hover事件。使用示例:// xxx.ets @Entry @Component struct HoverEventExample { @State hoverText: string = 'no hover'; @State color: Color = Color.Blue; build() { Column({ space: 20 }) { Button(this.hoverText) .width(180).height(80) .backgroundColor(this.color) .onHover((isHover: boolean, event: HoverEvent) => { // 通过onHover事件动态修改按钮在是否有鼠标或手写笔悬浮时的文本内容与背景颜色 // 通过event.sourceTool区分设备是鼠标还是手写笔 if (isHover) { if (event.sourceTool == SourceTool.Pen) { this.hoverText = 'pen hover'; this.color = Color.Pink; } else if (event.sourceTool == SourceTool.MOUSE) { this.hoverText = 'mouse hover'; this.color = Color.Red; } } else { this.hoverText = 'no hover'; this.color = Color.Blue; } }) }.padding({ top: 30 }).width('100%') } }本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。
鼠标滑动,或者手写笔在屏幕上悬浮移动扫过组件时触发。
onHover
onHover(event: (isHover: boolean, event: HoverEvent) => void): T
鼠标或手写笔进入或退出组件时触发hover事件。
使用示例:
本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。