移动开发
网络新概念,云计算、大数据、O2O、电商。。。。
网络新概念,云计算、大数据、O2O、电商。。。。
2017-12-20 08:14:00
WebView wv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); wv = (WebView)findViewById(R.id.webView); wv.getSettings().setJavaScriptEnabled(true); wv.addJavascriptInterface(this, "nativeMethod"); wv.loadUrl("file:///android_asset/index.html"); } @JavascriptInterface public void toActivity(String activityName) { //此处应该定义常量对应,同时提供给web页面编写者 if(TextUtils.equals(activityName, "a")){ startActivity(new Intent(this,AActivity.class)); }else{ startActivity(new Intent(this,BActivity.class)); } }
html
<!DOCTYPE HTML> <html> <script type="text/javascript"> function gotoActivity (activity) { nativeMethod.toActivity(activity); } </script> <body> <button onClick="gotoActivity('a')">gotoActivity A</button> <button onClick="gotoActivity('b')">gotoActivity B</button> </body> </html>
来自:http://www.cnblogs.com/already/p/6023648.html