简体   繁体   English

WebView打开链接,然后在浏览器中打开

[英]WebView opens link, then opens in browser

I have a WebView that is opening a Url for an article. 我有一个WebView正在打开文章的网址。 However, a couple of seconds after opening the link in the WebView, the browser opens up and loads the same article. 但是,在WebView中打开链接几秒钟后,浏览器打开并加载同一篇文章。 This is my activity: 这是我的活动:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_headline_web_view);

Intent intent = getIntent();
Uri headlineUri = intent.getData();

WebView webView = (WebView) findViewById(R.id.webView1);
webView.loadUrl(headlineUri.toString());
}

Thanks in advance! 提前致谢!

What happens if you add: 如果添加,会发生什么:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_headline_web_view);

    Intent intent = getIntent();
    Uri headlineUri = intent.getData();

    WebView webView = (WebView) findViewById(R.id.webView1);
    webview.setWebViewClient(new MyWebViewClient());
    webView.loadUrl(headlineUri.toString());
}

public class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return false;
    }
}

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

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