简体   繁体   English

Android WebView loadDataWithBaseURL链接href不支持

[英]Android WebView loadDataWithBaseURL link href not supporting

I have loaded HTML to my WebView with 我已经将HTML加载到我的WebView中了

webView.loadDataWithBaseURL("file:///android_asset/", getHTMLString(), "text/html", "UTF-8", "");

I want to open some pages using anchor Tag, but this is not working and showing error: 我想使用锚Tag打开一些页面,但这不起作用并显示错误:

<li ><a href="about_us.html" class="gn-icon gn-icon-download">About Us</a></li>
<li ><a href="contact_us.html" class="gn-icon gn-icon-download">Contact Us</a></li>

is it possible which I want to apply or not ?? 是否有可能我想申请? I want to avoid open new builtin Browser, pages should be behave like part of application, here is getHTMLString() method 我想避免打开新的内置浏览器,页面应该像应用程序的一部分,这里是getHTMLString()方法

String getHTMLString()
{
    String htmlString = "<HTML><Head><BODY>
    <ul>
    <li ><a href=\"about_us.html\" class=\"gn-icon gn-icon-download\">About Us</a></li>
    <li ><a href=\"contact_us.html\" class=\"gn-icon gn-icon-download\">Contact Us</a></li>
    </ul>
    </BODY></HEAD></HTML>";
    return htmlString;
}

Try to set WebViewClient with overrided onLoadResource . 尝试使用覆盖的onLoadResource设置WebViewClient
Once I've added this into my code, all pages started to open in the same WebView : 一旦我将其添加到我的代码中,所有页面都开始在同一个WebView打开:

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onLoadResource(WebView view, String url) {
            super.onLoadResource(view, url);
        }
    });

If you wouldn't receive such effect, you can parse url parameter manually and load needed html pages by yourself. 如果您不会收到此类效果,您可以手动解析url参数并自行加载所需的html页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM