软键盘的话可以监听软键盘弹出和收起,开启固定态输入法窗口软键盘高度变化的监听,获取当前的键盘高度,来规避内容被盖住的问题。也可以用expandSafeArea属性把组件扩展其安全区域:可以参考案例中的监听软键盘弹出和收起:import webview from '@ohos.web.webview'; import window from '@ohos.window'; @Entry @Component export struct SubWindowPage { @State webViewVisibility: Visibility = Visibility.Visible; private pageWidth = 320; private pageHeight = 500; private controller: webview.WebviewController = new webview.WebviewController(); @State flexAlign: FlexAlign = FlexAlign.Center @State screenHeight: number | string = '100%' aboutToAppear() { window.getLastWindow(getContext(this)).then(currentWindow => { // 监视软键盘的弹出和收起 currentWindow.on('avoidAreaChange', async data => { let property = currentWindow.getWindowProperties(); let avoidArea = currentWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); this.screenHeight = px2vp(property.windowRect.height - avoidArea.bottomRect.height); }); }) } build() { Stack() { Column() { Web({ src: $rawfile('index.html'), controller: this.controller }) .javaScriptAccess(true) .fileAccess(false) .zoomAccess(false) .domStorageAccess(true) .onlineImageAccess(true) .horizontalScrollBarAccess(false) .verticalScrollBarAccess(false) .cacheMode(CacheMode.Online) .width(this.pageWidth) .height(this.pageHeight) .border({ radius: 6 }) .visibility(this.webViewVisibility) .backgroundColor(Color.Pink) } .justifyContent(this.flexAlign) .alignItems(HorizontalAlign.Center) .width('100%') .height('100%') } .width('100%') .height(this.screenHeight) .backgroundColor('#999955') .alignContent(Alignment.Center) } }
软键盘的话可以监听软键盘弹出和收起,开启固定态输入法窗口软键盘高度变化的监听,获取当前的键盘高度,来规避内容被盖住的问题。
也可以用expandSafeArea属性把组件扩展其安全区域:
可以参考案例中的监听软键盘弹出和收起: