HarmonyOS webview输入框被遮挡

页面是webview 加载的H5页面, 点击输入框弹出键盘, 输入框被遮挡

HarmonyOS
2024-12-25 13:29:34
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

软键盘的话可以监听软键盘弹出和收起,开启固定态输入法窗口软键盘高度变化的监听,获取当前的键盘高度,来规避内容被盖住的问题。

也可以用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)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
分享
微博
QQ
微信
回复
2024-12-25 16:29:49
相关问题
HarmonyOS 键盘遮挡输入框
697浏览 • 1回复 待解决
HarmonyOS webview里的输入框键盘覆盖
676浏览 • 1回复 待解决
HarmonyOS web中的输入框键盘遮住
696浏览 • 1回复 待解决
HarmonyOS 密码输入框
768浏览 • 1回复 待解决
获取输入框输入的内容
447浏览 • 2回复 待解决
HarmonyOS 修改输入框焦点
724浏览 • 1回复 待解决
HarmonyOS 对话弹出页面遮挡
948浏览 • 1回复 待解决
HarmonyOS 适配-输入框问题
791浏览 • 1回复 待解决
HarmonyOS 输入框无法对齐
1117浏览 • 1回复 待解决
HarmonyOS 输入框只能输入字母和数字
1060浏览 • 1回复 待解决
HarmonyOS 输入框光标移位监听
841浏览 • 1回复 待解决
HarmonyOS textInput 如何清空输入框
897浏览 • 2回复 待解决