HarmonyOS H5执行文本框获取焦点,但web内不自动打开键盘

新开一个h5页面的web,初始化执行了一个input文本框的focus获取光标的事件,按道理应该会主动弹出键盘,但是没有弹出

HarmonyOS
2025-01-09 18:20:20
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

参考示例如下

import { webview } from '@kit.ArkWeb';
import { inputMethod } from '@kit.IMEKit';
import { BusinessError } from '@kit.BasicServicesKit';

let inputMethodController = inputMethod.getController();
@Entry
@Component
struct WebComponent {
  controller: webview.WebviewController = new webview.WebviewController();
  aboutToAppear(): void {
    webview.WebviewController.setWebDebuggingAccess(true)
    try {
      let textConfig: inputMethod.TextConfig = {
        inputAttribute: {
          textInputType: 0,
          enterKeyType: 1
        }
      };
      inputMethodController.attach(true, textConfig, (err: BusinessError) => {
        if (err) {
          console.error(`Failed to attach: ${JSON.stringify(err)}`);
          return;
        }
        console.log('Succeeded in attaching the inputMethod.');
      });
    } catch(err) {
      console.error(`Failed to attach: ${JSON.stringify(err)}`);
    }
  }
  build() {
    Scroll() {
      Column() {
        Web({
          src: $rawfile('demo.html'),
          controller: this.controller,
        })
          .onPageVisible(() => {
            inputMethodController.showTextInput().then(() => {
              console.log('Succeeded in showing text input.');
            }).catch((err: BusinessError) => {
              console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
            });
          })
          .domStorageAccess(true)
          .height('100%')
      }
    }
  }
}
  • 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.
分享
微博
QQ
微信
回复
2025-01-09 19:35:51
相关问题
H5页面输入自动获焦弹起软键盘
2627浏览 • 1回复 待解决
如何获取文本框里的文字宽度
2910浏览 • 1回复 待解决
HarmonyOS web组件加载h5h5拉起摄像头
1502浏览 • 1回复 待解决
HarmonyOS 如何获取文本框中光标高度
661浏览 • 1回复 待解决
HarmonyOS webH5交互
1560浏览 • 1回复 待解决
HarmonyOS Web组件加载H5白屏
874浏览 • 1回复 待解决
HarmonyOS 如何修改H5的localstorage
561浏览 • 1回复 待解决
页面类似弹样式跳转H5
694浏览 • 1回复 待解决
Web中webview和H5交互
1815浏览 • 1回复 待解决
HarmonyOS web原生和H5如何交互?
1427浏览 • 1回复 待解决
HarmonyOS web通过loadData加载h5标签
1301浏览 • 1回复 待解决
HarmonyOS H5打开原生相机
737浏览 • 1回复 待解决
textinput 文本框是否可以分段展示?
664浏览 • 1回复 待解决
HarmonyOS h5 web上传图片,文件的demo
763浏览 • 1回复 待解决