Android的WebView中不推出新的浏览器 [英] Android WebView NOT launching new browser

查看:181
本文介绍了Android的WebView中不推出新的浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

previously。

Previously when using a webview in android, clicking any link would force the "proper" browser to open and then web browsing would continue in that instance.

然而,这似乎不再是这种情况。下面code导致停留在网页视图内的所有链接,但其实我是想的链接,启动一个新的浏览器实例。这样做改变2.3?

However this seems to no longer be the case. The following code results in all links staying inside the webview, but I actually want the links to launch a new browser instance. Did this change in 2.3 ?

请注意,我问的是大多数人问对面(他们问如何保持网页视图中的所有环节,我希望他们在外面发射)

Note I am asking the opposite of what most people ask (they ask how to keep all links inside the webview, I want them to launch outside)

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        WebView view = new WebView(this);
        setContentView(view);

        view.loadUrl("http://news.bbc.co.uk");

    }
}

编辑:澄清 - 第一个URL将在WebView中载入和所有后续的点击将打开一个新的浏览器。这是我真正想要的简单,但足够好了。

Clarification - the first URL will load in the WebView and all subsequent clicks will open in a new browser. This is simplification from what I really want, but good enough.

Bascially问题是,previously单击链接会打开一个新的浏览器会话。大多数人不希望(在这里它因此问题),但我做的。但是由于某种原因,现在看来在web视图来加载所有的时间(也许是2.3?)

Bascially the problem is, previously clicking a link would open a new browser session. Most people don't want that (hence the questions on here about it) but I do. However for some reason now it seems to load in the webview all the time (2.3 perhaps?)

推荐答案

让我明白了。你要启动在同一个web视图的第一个网页,而其他的超链接转到默认浏览器,或者你想浏览器默认打开第一个链接点击?

Let me understand. Do you want to launch the first webpage in the same webview, while the other hyperlinks to go to the default browser, or you want the default browser itself to open for the first link clicked?

如果是第一种情况,我不知道到底,除非你知道一些方法来收集来自网页流量的链接网址。

If it's the first case, I don't exactly know, unless you know some way to gather the link URL from the webview.

对于第二个实例,即启动默认浏览器的任何URL点击,只需跳过(删除)此行: view.setWebViewClient(新WebViewClient(){}); ,这将打开在默认浏览器的所有环节,而不是web视图本身。

For the second instance, i.e. launching the default browser for any URL click, just skip (remove) this line: view.setWebViewClient(new WebViewClient() { });, which will open all the links in the default browser, and not the webview itself.

这篇关于Android的WebView中不推出新的浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆