引用:http://www.oschina.net/code/snippet_97818_4400
[代码] java bean代码
04 |
public void setTitle(String title){
|
08 |
public String getTitle(){
|
[代码] android端
01 |
package com.xu81.tw4a;
|
03 |
import java.util.List;
|
05 |
import android.app.Activity;
|
06 |
import android.webkit.WebChromeClient;
|
07 |
import android.webkit.WebSettings;
|
08 |
import android.webkit.WebView;
|
10 |
public class TiddlyWiki4Android extends Activity {
|
12 |
private WebView mainWebView;
|
14 |
/** Called when the activity is first created. */
|
16 |
public void onCreate(Bundle savedInstanceState) {
|
17 |
super .onCreate(savedInstanceState);
|
18 |
setContentView(R.layout.main);
|
21 |
mainWebView = (WebView) findViewById(R.id.mainWebView);
|
23 |
WebSettings setting = mainWebView.getSettings();
|
24 |
setting.setJavaScriptEnabled( true );
|
25 |
mainWebView.setWebChromeClient( new WebChromeClient());
|
28 |
mainWebView.addJavascriptInterface(b, "bean" );
|
29 |
mainWebView.loadUrl( "file:///android_asset/test.html" );//加载本地html页面
|
[代码] javascript端调用方式
2 |
var bean = window.bean;
|
3 |
var title = bean.getTitle();
|