在看懂这篇文章之前首先要有javascript基础。
(1) js调用android的方法:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
wView = (WebView)findViewById(R.id.wv1);
WebSettings wSet = wView.getSettings();
wSet.setJavaScriptEnabled(true);
ProxyBridge pBridge = new ProxyBridge();
wView.addJavascriptInterface(pBridge, "AliansBridge");
wView.loadUrl("file:///android_asset/index.html");
}
private class ProxyBridge {
public int one () {
return 1;
}
}
}
<a onClick="window.demo.clickOnAndroid()">
<div style="width:100px;
margin:0px auto;
padding:10px;
text-align:center;
border:2px solid #202020;" >
<img id="droid" src="android_normal.png" mce_src="android_normal.png"/><br>
Click me!
</div>
</a>
<input type="submit" value="change to 1" onclick="document.getElementById('output').innerHTML
=AliansBridge.one()" />
</body>
</html>
新闻热点
疑难解答
图片精选