从Android的web视图正常浏览器弹出打开链接 [英] Open link from Android Webview in normal browser as popup

查看:101
本文介绍了从Android的web视图正常浏览器弹出打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有什么是basicly一个简单的WebView至极加载页面。这个页面有一个web视图中打开几个环节。这就是它应该做的,所以它的工作一切正常。

So what I have is basicly a simple webview wich loads a page. This page has a few links that opens within the webview. That's what it supposed to do, so it's working all fine.

但有一个从该页面至极应加载一个弹出式单条链路,所以我希望它在正常的浏览器中打开,当人们点击它。但正如我所说,各个环节都开设在web视图,以便链接,它也。

But there is one single link from that page wich should load as a popup, so I want it to open in the normal browser when people click it. But as I stated, all links are opening in the webview, so that link does it also.

我的问题是,我怎样才能使这个环节,在普通的浏览器作为一种弹出的打开?它甚至有可能?链接是可变的,所以它总是在变化,它不能应用在新的浏览器浏览器打开内很难codeD。

My question is, how can I make this link open in the normal browser as a kind of a popup? Is it even possible? The link is variable so it's changing always, it cannot be hardcoded within the application to open in a new browser browser.

谁能告诉我,如果这是可能的,怎么办呢?非常感谢!

Can someone tell me if it's possible and how to do it? Thank you very much!

推荐答案

下面是压倒一切的WebView加载一个例子,留在你的web视图中或离开:

Here's an example of overriding webview loading to stay within your webview or to leave:

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class TestWebViewActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        WebView webView = (WebView) findViewById(R.id.webview);
        webView.setWebViewClient(new MyWebViewClient());
    }
}


class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(url.contains("somePartOfYourUniqueUrl")){ // Could be cleverer and use a regex
            return super.shouldOverrideUrlLoading(view, url); // Leave webview and use browser
        } else {
            view.loadUrl(url); // Stay within this webview and load url
            return true;
        }
    }
}

这篇关于从Android的web视图正常浏览器弹出打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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