Android WebView链接无法打开

时间:2015-12-12 10:53:08

标签: android webview

如何点击我加载的WebView数据中提供的链接?

加载的WebView数据采用HTML格式:

<P CLASS="western" ALIGN=JUSTIFY STYLE="margin-bottom: 0.14in">Further
<A HREF="google.com">here</A></P>

WebView位于滚动视图内,其webClient为:

webViewClient = new WebViewClient()
        {
            @Override
            public boolean shouldOverrideUrlLoading(WebView  view, String  url)
            {
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onLoadResource(WebView  view, String  url)
            {
            }
        };

        webView = (WebView) findViewById(R.id.tos);                                 // Defining the WebView for the terms and conditions and loading the required data
        webView.setWebViewClient(webViewClient);
        webView.loadData(getResources().getString(R.string.terms_of_service), "text/html", "UTF-8");

问题是,当我点击链接时,不会发生任何操作。怎么解决这个问题?

1 个答案:

答案 0 :(得分:0)

使用此代码打开

WebView webView;//make sure to initialize  
webView.setWebViewClient(webViewClient);

WebViewClient webViewClient= new WebViewClient(){
    @Override
    public boolean shouldOverrideUrlLoading(WebView  view, String  url){
        return true;
    }
    @Override
    public void onLoadResource(WebView  view, String  url){
        if( url.equals("http://yoururl.com") ){
            // do something
        }
    }
}