标签:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
WebView webview = (WebView)findViewById(R.id.vew);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.baidu.com");
webview.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>demo</title>
<script>
function wave(){
document.getElementById(‘button‘).value = ‘aaaaaaa‘;
}
</script>
</head>
<body>
<input type="button" id="button" value="点我试试看" onClick="alert(1);window.demo.clickOnAndroid()" />
</body>
</html>
WebView webview;
private Handler mHandler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = (WebView)findViewById(R.id.vew);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webview.addJavascriptInterface(new androidclick() , "demo");
webview.loadUrl("file:///android_asset/demo.html");
}
private final class androidclick{
public void clickOnAndroid(){
mHandler.post(new Runnable() {
public void run() {
webview.loadUrl("javascript:wave()");
}
});
}
}
标签:
原文地址:http://www.cnblogs.com/lzqbk/p/d7f0adba7b692e89ff837d179f4399a4.html