可以使用窗口相关接口获取软键盘高度,代码如下:aboutToAppear() { window.getLastWindow(getContext(this)) .then(currentWindow => { //获取windowClass对象 let property = currentWindow.getWindowProperties(); //方式1:获取规避区域 let avoidArea = currentWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); // 初始化显示区域高度 this.screenHeight = px2vp(property.windowRect.height - avoidArea.bottomRect.height); // 监视软键盘的弹出和收起 currentWindow.on('avoidAreaChange', async data => { if (data.type !== window.AvoidAreaType.TYPE_KEYBOARD) { return; } this.screenHeight = px2vp(data.area.bottomRect.height); console.log(this.screenHeight + '' + 'foo xxx' ) //控制台输出可以看到键盘的高度 } ) //方式2:直接获取软键盘高度 currentWindow.on('keyboardHeightChange', data => { console.log("foo data" + px2vp(data)) //控制台输出可以看到键盘的高度 } ) }) }参考链接为:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5
可以使用窗口相关接口获取软键盘高度,代码如下:
参考链接为:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5