HarmonyOS鸿蒙Next中如何监听键盘变化

HarmonyOS鸿蒙Next中如何监听键盘变化

ArkUI 开发框架在 '@ohos.window' 模块里提供了对键盘高度变换的监听

// 引入模块
import window from '@ohos.window';

// 监听键盘高度变化
private monitorKeyboardHeightChanged() {
  let context = getContext(this) as Context
  window.getLastWindow(context).then((lastWindow) => {
    lastWindow.on("keyboardHeightChange", (height) => {
      console.log("keyboardHeightChanged: " + height)
    })
  }).catch((error) => {
    console.log("getLastWindow error: " + error)
  })
}

更多关于 HarmonyOS鸿蒙Next中如何监听键盘变化 的实战教程也可以访问 https://www.itying.com/category-93-b0.html

回到顶部