2015-05-15 70 views
2

我有一个header.html文件& a footer.html文件在我的assets/html/文件夹中。使用LoadUrl在Android的WebView中使用LoadUrl包装内容

这里是我的代码来创建和填充我WebView与内容:

WebView contentView = (WebView) view.findViewById(R.id.contentView); 
String contentText = Function.OBJECT.get("info").toString(); 

contentView.loadData(contextText, "text/html", null); 

如何包装contextTextheader.htmlfooter.html和存在于WebView输出?

回答

0

如果我正确理解你的话,你想解析header.html和footer.html,并在它们之间放置一些内容。

通过使用WebView.loaddata(),您告诉WebView使用String作为内容,但这不是您想要的。通过Javascript/Jquery绑定/追加header.html/footer.html中的内容到这些div(jquery append external html file into my page),并使用WebView.loadUrl()将index.html/footer div绑定/附加到这些div()从资产加载新的index.html:

public class MainActivity extends ActionBarActivity { 

private WebView mWebView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    mWebView = (WebView) findViewById(R.id.activity_main_webview); 

    WebSettings webSettings = mWebView.getSettings(); 
    webSettings.setJavaScriptEnabled(true); 

    String url =("file:///android_asset/index.html"); 

    mWebView.loadUrl(url); 
    } 
} 
相关问题