Android:如何监听webView中弹出的软键盘????急求!!
1条回答
- Moluth 2016-07-15 08:51关注
使用js监听,然后,调用安卓中的方法,将值传给安卓即可
public class MainActivity extends Activity { WebView wv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); wv=(WebView) findViewById(R.id.wv); wv.setWebViewClient(new WebViewClient()); initData(); } private void initData() { wv=(WebView) findViewById(R.id.wv); wv.setWebViewClient(new WebViewClient());//防止跳转到手机浏览器 WebSettings settings = wv.getSettings(); settings.setJavaScriptEnabled(true);////启用javascript //指定可供js调用的java对象 wv.addJavascriptInterface(new A(), "bridge"); wv.loadUrl("file:///android_asset/a.html"); } public class A { @JavascriptInterface public void show(String s) { Toast.makeText(MainActivity.this, s, 0).show(); } } }
下面是a.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script type="text/javascript"> function aa() { var w=document.getElementById("hhh"); w.style.backgroundColor="#ff0000"; } function show() { w=document.getElementById("input"); bridge.show(w.value); } </script> </head> <body> <div style="background-color:#335577; width:30px; height:50px" id="hhh"> </div> <input type="text" id="input" /> <button onClick="aa();">哈哈</button><br/> <button onClick="show();">哈哈</button> </body> </html>
解决 无用评论 打赏 举报
悬赏问题
- ¥15 ads仿真结果在圆图上是怎么读数的
- ¥20 Cotex M3的调试和程序执行方式是什么样的?
- ¥20 java项目连接sqlserver时报ssl相关错误
- ¥15 一道python难题3
- ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
- ¥15 牛顿斯科特系数表表示
- ¥15 arduino 步进电机
- ¥20 程序进入HardFault_Handler
- ¥15 oracle集群安装出bug
- ¥15 关于#python#的问题:自动化测试