OpenHarmony 5.0无法监听按键

目录

1.背景

二.解决方案


1.背景

        如下代码:

Button($r('app.string.ItemTest_key_volume_up'))
          .onKeyEvent((event: KeyEvent) => {
            this.changBackground(event)
          })

上述代码发现在OpenHarmony 3.2中是可以监听到音量键以及其他按键的事件的,然而在OpenHarmony 5.0中尝试是监听不到,看了官网资料也是和上述写法差不多,如下:

OpenAtom OpenHarmony

// xxx.ets
@Entry
@Component
struct KeyEventExample {
  @State text: string = ''
  @State eventType: string = ''

  b

你可能感兴趣的:(OpenHarmony,5.0(鸿蒙next),harmonyos,华为)