1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > android虚拟按键弹出 自动弹出虚拟键盘

android虚拟按键弹出 自动弹出虚拟键盘

时间:2021-08-28 00:09:44

相关推荐

android虚拟按键弹出 自动弹出虚拟键盘

### 使用Native.js实现打开页面默认弹出软键盘

~~~

var nativeWebview, imm, InputMethodManager;

var initNativeObjects = function() {

if (mui.os.android) {

var main = plus.android.runtimeMainActivity();

var Context = plus.android.importClass("android.content.Context");

InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");

imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);

} else {

nativeWebview = plus.webview.currentWebview().nativeInstanceObject();

}

};

var showSoftInput = function() {

var nativeWebview = plus.webview.currentWebview().nativeInstanceObject();

if (mui.os.android) {

//强制当前webview获得焦点

plus.android.importClass(nativeWebview);

nativeWebview.requestFocus();

imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);

} else {

nativeWebview.plusCallMethod({

"setKeyboardDisplayRequiresUserAction": false

});

}

setTimeout(function() {

//此处可写具体逻辑设置获取焦点的input

var input = mui("#myinput")[0];

input.focus();

}, 200);

};

mui.plusReady(function() {

initNativeObjects();

showSoftInput();

});

~~~

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。