webview links not working

2019-02-23 17:36发布

l am using webview in my xml, loading html file from asset directory. But clicking on links sometimes launching browser on first click and sometimes not responding even after 5 clicks.

Any help is appreciated.

Thanks

2条回答
一纸荒年 Trace。
2楼-- · 2019-02-23 17:53

For, this you've to use WebViewClient() to your WebView

WebView web = (WebView)findViewById(R.id.webView1);
.....
.....   // Your stuff
.....
web.setWebViewClient(new HelloWebViewClient());


public class HelloWebViewClient extends WebViewClient
{
    public HelloWebViewClient()
    {
        // do nothing
    }

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

    @Override
    public void onPageFinished(WebView view, String url)
    {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);
    }
}
查看更多
欢心
3楼-- · 2019-02-23 18:02

just add these lines

webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
查看更多
登录 后发表回答