HarmonyOS 点击系统键盘的隐藏按钮,不自动失焦,需要手工触发下别的位置才可以触发失焦

用H5的一个输入框拉起原生键盘,在完成输入之后,点击键盘上的收起/隐藏键,键盘隐藏,但是输入框并未失焦。如何监听到H5页面上的输入框拉起的键盘的收起/隐藏事件?

HarmonyOS
2024-11-27 09:22:14
1115浏览
已于2024-11-27 09:23:11修改
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

​用H5的一个输入框拉起原生键盘,在完成输入之后,点击键盘上的收起/隐藏键,键盘隐藏,不会自动触发失焦。是正常的。如果想要失焦的效果需要开发者自行完善逻辑。

监听键盘出现和隐藏通过window.on(‘keyboardHeightChange’)事件,返回高度为0表示键盘隐藏,不为0表示弹出键盘,每次弹出或隐藏键盘均只触发一次

h5中点击系统键盘的完成按钮,不自动收起键盘,这是当前的规格,并不属于bug

参考链接:​https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#ZH-CN_TOPIC_0000001884757714__onkeyboardheightchange7

参考demo:​

import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; 
import { hilog } from '@kit.PerformanceAnalysisKit'; 
import { window } from '@kit.ArkUI'; 
import { BusinessError } from '@kit.BasicServicesKit'; 
 
export default class EntryAbility extends UIAbility { 
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); 
  } 
 
  onDestroy(): void { 
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); 
  } 
 
  onWindowStageCreate(windowStage: window.WindowStage): void { 
    // Main window is created, set main page for this ability 
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 
 
    windowStage.loadContent('pages/Index', (err) => { 
      if (err.code) { 
        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); 
        return; 
      } 
 
      // 获取应用主窗口。 
      let windowClass: window.Window | undefined = undefined; 
 
      windowStage.getMainWindow((err: BusinessError, data) => { 
        let errCode: number = err.code; 
        if (errCode) { 
          console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 
          return; 
        } 
        windowClass = data; 
        console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 
 
        try { 
          //开启固定态输入法窗口软键盘高度变化的监听。 
          windowClass.on('keyboardHeightChange', (data) => { 
            console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); 
          }); 
        } catch (exception) { 
          console.error(`Failed to enable the listener for keyboard height changes. Cause code: ${exception.code}, message: ${exception.message}`); 
        } 
      }) 
 
      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); 
    }); 
  } 
 
  onWindowStageDestroy(): void { 
    // Main window is destroyed, release UI related resources 
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); 
  } 
 
  onForeground(): void { 
    // Ability has brought to foreground 
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); 
  } 
 
  onBackground(): void { 
    // Ability has back to background 
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
分享
微博
QQ
微信
回复
2024-11-27 15:00:50
相关问题
HarmonyOS RichEditor 获/问题
1046浏览 • 1回复 待解决
H5页面输入框自动弹起软键盘
2648浏览 • 1回复 待解决
Stack组件中如何触发下层事件控件
726浏览 • 1回复 待解决
应用通用获及走方式如何实现
2661浏览 • 1回复 待解决
HarmonyOS TextInput意外获
904浏览 • 1回复 待解决
HarmonyOS onKeyEvent 按钮触发
572浏览 • 1回复 待解决