打开对话框选择浏览器 [英] Open dialog to choose browser

查看:161
本文介绍了打开对话框选择浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中一个网址加载网页视图,其中有一些链接直接点击,但问题是,当我点击它在默认浏览器中打开的WebView加载页面上的链接,我想打开一个包含所有的浏览器对话框当我的链接,这是在设备单击,要求来选择浏览器,它应该在选择的浏览器中打开?

I have a webview in which a url is loaded, which has some url to be clickable, but the problem is when i click the links on page loaded in webview it opens in default browser, i want to open dialog containing all browsers when i click on link, which are in device, to ask to choose the browser and it should open in the browser selected ?

推荐答案

改变默认单击行为

当用户点击了网页视图链接上的默认行为是加载任何默认的应用程序可以处理的链接。所以,如果你点击一个网站的网址时,浏览器会打开来处理它。如果你试图在本地构建的网页间导航,你需要重写此功能。幸运的是,这是不是很难处理。你可以这样做超快你的WebView的WebViewClient设置为WebViewClient的,像这样一个新的实例:

when the user clicks on a link in the WebView the default behavior is to load whatever default app can handle the link. So if you click on a web URL, the browser will open to handle it. If you were trying to navigate between locally built web pages, you’d need to override this functionality. Luckily this is not difficult to handle. You can do it super quick by setting the WebViewClient of your WebView to a new instance of WebViewClient like so:

在OnCreate:

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

    WebView webView = (WebView) findViewById(R.id.webView1);

    WebViewClient viewClient = new WebViewClient(){

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url)); 
            startActivity(intent); 
            view.loadUrl(url);
            return true;

        }
    };

    webView.setWebViewClient(viewClient);
    webView.loadUrl("http://www.google.com");
}

检查以下链接上WebViewClient更多信息

Check the below link for more info on WebViewClient

处理中的链接网页视图

这篇关于打开对话框选择浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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