0

我有一个 WebView 正在为一篇文章打开一个 Url。但是,在 WebView 中打开链接几秒钟后,浏览器会打开并加载同一篇文章。这是我的活动:

@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());
}

提前致谢!

4

1 回答 1

1

如果添加会发生什么:

@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;
    }
}
于 2013-10-14T21:18:26.153 回答