监听软键盘的可以通过两个方式:通过输入法框架模块来监听(@ohos.inputMethod)用InputMethodController实例的on('sendKeyboardStatus')方法来监听,直接在inputMethodController.on('sendKeyboardStatus', callback)的callback中处理。通过输入法框架模块来监听软键盘状态参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-inputmethod-V5\#onsendkeyboardstatus10通过窗口模块来监听(@ohos.window)用Window实例的on('keyboardHeightChange')方法来监听软键盘高度,也能判断软键盘状态的。通过窗口模块来监听软键盘状态参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5\#onkeyboardheightchange7示例代码:let windowClass: window.Window | undefined = undefined; try { window.getLastWindow(this.context, (err: BusinessError, data) => { const errCode: number = err.code; if (errCode) { console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); return; } windowClass = data; console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); windowClass.on('avoidAreaChange', (data) => { console.info('Succeeded in enabling the listener for system avoid area changes. type:' + JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area)); }); }); } catch (exception) { console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); }
监听软键盘的可以通过两个方式:通过输入法框架模块来监听(@ohos.inputMethod)用InputMethodController实例的on('sendKeyboardStatus')方法来监听,直接在inputMethodController.on('sendKeyboardStatus', callback)的callback中处理。
通过输入法框架模块来监听软键盘状态参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-inputmethod-V5\#onsendkeyboardstatus10
通过窗口模块来监听(@ohos.window)用Window实例的on('keyboardHeightChange')方法来监听软键盘高度,也能判断软键盘状态的。
通过窗口模块来监听软键盘状态参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5\#onkeyboardheightchange7
示例代码: