过滤网站访问权限后,我将HTML页面加载到WebView中。
当我单击超文本链接时,不被调用shouldOverrideUrlLoading(),但是被调用了onPageFinished()。 onPageFinished的url参数是“ about:blank”。结果是将下一页设置为空白。
经过类似问题的扫描后,没有人帮助解决该问题。
为什么不调用shouldOverrideUrlLoading(),或者如何更改?
文本中的超文本链接为“({Text1 Text2)”。
代码是:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// prepare webview
rootView = inflater.inflate(R.layout.my_view, container, false);
webView = (WebView) rootView.findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
HtmlProvider provider = new HtmlProvider();
provider.readWebpage( this);
webView.setBackgroundColor( userSettings.chapterPageBgColor);
webView.setWebViewClient( new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading( WebView view, String url) {
// ** never coming here **
webView.loadUrl( htmlBase + url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
});
return rootView;
}
// When the webpage is received via an asynchonous call, this method is called.
private void formatHtmlContent(String content) {
String htmlBegin = "<!DOCTYPE html><head><style>body { font-size: 120%; } </style><meta charset=\"utf-8\" /> " +
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"> " +
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"></head><body text=\"#acolor\">";
String htmlEnd = "</body></html>";
webView.loadDataWithBaseURL(null, htmlBegin + content + htmlEnd, "text/html", "UTF-8", null);
}