如果我理解正确,您想解析 header.html 和 footer.html 并在两者之间放置一些内容。
通过使用 WebView.loaddata() 您告诉 WebView 使用字符串作为内容,但这不是您想要的。
制作 index.html、添加页眉/页脚 div、通过 Javascript/Jquery 将 header.html/footer.html 中的内容绑定/附加到这些 div(jquery 将外部 html 文件附加到我的页面)并使用 WebView 更容易。 loadUrl() 从资产中加载新的 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);
}
}