我使用以下代码来加载电子书的HTML内容,其中templateString包含HTML内容,该内容连接到主文件中的样式表和图像。
我面临的问题是锚点链接完全不响应。
我注意到如果itemURL为空,或者使用loadData而不是loadDataWithBaseURL,那么链接会正常工作,但我会失去通过itemURL连接的图像和样式的联系。
请注意,webview的可见性始终设置为可见。我已向webview添加以下功能。
这是为WebView初始化的onTouch方法:
如果需要进一步的代码,我可以分享它。
String itemURL = "file://" + itemPath;
testWV.loadDataWithBaseURL(itemURL, templateString, "text/html", "UTF-8", "about:blank");
我面临的问题是锚点链接完全不响应。
我注意到如果itemURL为空,或者使用loadData而不是loadDataWithBaseURL,那么链接会正常工作,但我会失去通过itemURL连接的图像和样式的联系。
请注意,webview的可见性始终设置为可见。我已向webview添加以下功能。
this.getSettings().setJavaScriptEnabled(true);
this.requestFocusFromTouch();
this.setVerticalScrollBarEnabled(false);
this.setHorizontalScrollBarEnabled(false);
this.getSettings().setSupportZoom(true);
this.getSettings().setBuiltInZoomControls(true);
this.getSettings().setDisplayZoomControls(false);
this.getSettings().setAllowContentAccess(true);
this.getSettings().setAllowFileAccess(true);
this.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
this.getSettings().setAllowFileAccessFromFileURLs(true);
this.getSettings().setAllowUniversalAccessFromFileURLs(true);
这是为WebView初始化的onTouch方法:
this.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
WebView.HitTestResult hr = ((WebView)v).getHitTestResult();
System.out.println("getExtra: "+hr.getExtra());
// getExtra always gives null when webview loaded with loadDataWithBaseURL while it should give the url of the link pressed when the user touches a link
return false;
}
});
如果需要进一步的代码,我可以分享它。
href
URL相同吗? - Priyanka