问题场景用H5的一个输入框拉起原生键盘,在完成输入之后,点击键盘上的收起/隐藏键,键盘隐藏,但是输入框并未失焦。如何监听到H5页面上的输入框拉起的键盘的收起/隐藏事件?用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'); } }
问题场景
用H5的一个输入框拉起原生键盘,在完成输入之后,点击键盘上的收起/隐藏键,键盘隐藏,但是输入框并未失焦。如何监听到H5页面上的输入框拉起的键盘的收起/隐藏事件?
用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: