HarmonyOS Web输入框中键盘mode模式问题?

Web页面中的input输入框,点击输入框弹出键盘,是抬起的模式,对组件设置:

windowStage.getMainWindowSync().getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE);  

不起作用,想要的是,弹出键盘后,键盘是遮盖到页面上,不改变原有Web的UI。

阅读 540
1 个回答

可以考虑使用layoutMode自适应布局,并将Web组件内嵌到可滚动容器实现页面滑动:

import web_webview from '@ohos.web.webview'
import { KeyboardAvoidMode } from '@ohos.arkui.UIContext'
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
@Entry
@Component
struct WebComponent {
  private scrollerForScroll: Scroller = new Scroller()
  controller: web_webview.WebviewController = new web_webview.WebviewController();
  // scroll竖向的滚动
  @State ScrollDirection: ScrollDirection = ScrollDirection.Vertical
  build() {
    Flex() {
      Scroll(this.scrollerForScroll) {
        Column({ space: 5 }) {
          Web({ src: $rawfile('web2.html'), controller: this.controller })
            .nestedScroll({
              scrollForward: NestedScrollMode.SELF_FIRST,
              scrollBackward: NestedScrollMode.SELF_FIRST
            })
            .height("100%")
            .width("100%")
            .layoutMode(WebLayoutMode.FIT_CONTENT)
        }.width("95%")
      }
      .scrollBar(BarState.Off)
      .width("100%")
      .height("120%")
      .scrollable(this.ScrollDirection)
    }.width('100%').height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进