mui开发App中,使用nativejs设置input焦点并触发软键盘
2017-08-21 00:00
501 查看
摘要: 项目需要,打开搜索页面时设置input获取焦点并弹出软键盘。
调用:
效果:
var showSoftInput= function(id) { var nativeWebview, imm, InputMethodManager; //初始化NativeObject 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 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 inputObj = document.getElementById(id); inputObj.focus(); }, 200); };
调用:
document.addEventListener("plusready", function() { showSoftInput("keyword"); });
效果:
相关文章推荐
- 利用HBuilder开发基于MUI的H5+ app中使用百度地图定位功能
- MUI开发APP文本框获得焦点并弹出软键盘
- mui开发APP教程之使用选项卡跳转子页面
- 利用HBuilder开发基于MUI的H5+ app中使用百度地图定位功能
- 使用ionic开发手机app中,设置tab中的icon为自定义图标的方法
- iOS开发-SQLite数据库在App项目中的设置及使用
- 移动App开发 MUI框架 利用软键盘的搜索键实现页面跳转并传值
- 使用Hbuilder和MUI开发Hybird app笔记
- 聊天记录,踩的坑:设置EditText焦点;EditText软键盘和recyclerview的交互;SpannableStringBuilder的使用;ClickableSpan失效;软键盘挡住edi
- Hbuilder,使用mui,HTML5 plus 开发Android,IOS的APP始末
- 懂商业的技术合伙人(14):使用HTML5开发App客户端,HTML5+和MUI框架基本介绍
- Hbuilder,使用mui,HTML5 plus 开发Android,IOS的APP始末
- 设置TextInput控件获得焦点时边框的某一角为圆角.
- 简化 Ajax 和 Java 开发,第 2 部分: 使用约定最小化设置
- 使用Eclipse+MyEclipse开发中的编码设置
- 使用C#和Excel进行报表开发(七)-设置单元格的显示格式
- Java 开发 2.0: 使用 Google App Engine
- 使用Google App Engine开发中遇到的几个错误
- Debian下使用eclipse设置Android开发环境
- Flex中如何利用FocusManager类的setFocus函数,设置TextInput的焦点