HarmonyOS Web组件加载H5,拉起软键盘遮挡输入框

H5页面底部有个输入弹框,拉起软件盘后,遮挡了输入弹框部分,如何处理

HarmonyOS
2024-12-25 14:15:09
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

拉起键盘web内容会上浮的,可参考这个demo

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)
          .width('100%')
          .height(this.pageHeight)
          .height('100%')
          .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)
  }
}
分享
微博
QQ
微信
回复
2024-12-25 16:50:31
相关问题
H5页面输入框自动获焦弹起软键盘
2044浏览 • 1回复 待解决
HarmonyOS 输入框软键盘问题
250浏览 • 1回复 待解决
HarmonyOS 键盘遮挡输入框
213浏览 • 1回复 待解决
HarmonyOS web组件加载h5h5拉起摄像头
870浏览 • 1回复 待解决
关于软键盘弹出遮挡问题
1419浏览 • 1回复 待解决
HarmonyOS webview输入框遮挡
259浏览 • 1回复 待解决
HarmonyOS Web组件加载H5白屏
275浏览 • 1回复 待解决
HarmonyOS web中的输入框键盘遮住
286浏览 • 1回复 待解决
HarmonyOS 软键盘挤压Toast弹
154浏览 • 1回复 待解决
HarmonyOS Web输入框键盘mode模式问题
297浏览 • 1回复 待解决