• Lv0
    粉丝0

积分77 / 贡献0

提问30答案被采纳0文章0

焦点事件onBlur/onFocus回调无法触发

Summer 显示全部楼层 发表于 2023-9-5 09:36:30
【问题描述】
按照官网的示例,运行代码,点击按钮时,焦点事件onBlur/onFocus回调无法触发。

AgAABXjTvQPt2joMLs5G85ju-wXEPrfF.png

代码:
  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct FocusEventExample {
  5.   @State oneButtonColor: string = '#FFC0CB'
  6.   @State twoButtonColor: string = '#87CEFA'
  7.   @State threeButtonColor: string = '#90EE90'

  8.   build() {
  9.     Column({ space: 20 }) {
  10.       // 通过外接键盘的上下键可以让焦点在三个按钮间移动,按钮获焦时颜色变化,失焦时变回原背景色
  11.       Button('First Button')
  12.         .backgroundColor(this.oneButtonColor)
  13.         .width(260)
  14.         .height(70)
  15.         .fontColor(Color.Black)
  16.         .focusable(true)
  17.         .onFocus(() => {
  18.           this.oneButtonColor = '#FF0000'
  19.         })
  20.         .onBlur(() => {
  21.           this.oneButtonColor = '#FFC0CB'
  22.         })
  23.       Button('Second Button')
  24.         .backgroundColor(this.twoButtonColor)
  25.         .width(260)
  26.         .height(70)
  27.         .fontColor(Color.Black)
  28.         .focusable(true)
  29.         .onFocus(() => {
  30.           this.twoButtonColor = '#FF0000'
  31.         })
  32.         .onBlur(() => {
  33.           this.twoButtonColor = '#87CEFA'
  34.         })
  35.       Button('Third Button')
  36.         .backgroundColor(this.threeButtonColor)
  37.         .width(260)
  38.         .height(70)
  39.         .fontColor(Color.Black)
  40.         .focusable(true)
  41.         .onFocus(() => {
  42.           this.threeButtonColor = '#FF0000'
  43.         })
  44.         .onBlur(() => {
  45.           this.threeButtonColor = '#90EE90'
  46.         })
  47.     }.width('100%').margin({ top: 20 })
  48.   }
  49. }
复制代码


【运行环境】
硬件:rk3568;  ROM:  4.0 Beta1 ;  API 10




您尚未登录,无法参与评论,登录后可以:
参与开源共建问题交流
认同或收藏高质量问答
获取积分成为开源共建先驱

精彩评论1

沙发 发表于 2023-9-7 14:24:16
提示: 作者被禁止或删除 内容自动屏蔽

Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

返回顶部