"完成动作用"想在web视图加载时 [英] "Complete action using" when trying to load in a WebView

查看:94
本文介绍了"完成动作用"想在web视图加载时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试内置的web视图中的Andr​​oid应用程序。我的问题是下面的code

 的WebView web视图=(web视图)findViewById(R.id.webView1);
webView.loadUrl(http://google.com);
 

触发意图(sugesting的安装的浏览器打开网络)而不是打开它在内置的web视图。我应该怎么做,以避免呢?

解决方案

 的WebView mWebView =(web视图)findViewById(R.id.webView1);
mWebView.setWebViewClient(新WebViewClient(){
        @覆盖
        公共无效onReceivedError(web视图来看,INT错误code,
                字符串描述,字符串failingUrl){
            //处理错误
        }

        @覆盖
        公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
            view.loadUrl(URL);
            返回true;
        }
    });

mWebView.loadUrl(http://google.com);
 

这将不会打开其他broweser。有参考这里开发者的网站

I'm testing the built-in WebView in the Android apps. My problem is that the following code

WebView webView = (WebView) findViewById(R.id.webView1);
webView.loadUrl("http://google.com");

triggers an intent (sugesting the installed browsers for opening the web) instead of open it in the built-in WebView. What should I do for avoiding that?

解决方案

WebView mWebView= (WebView) findViewById(R.id.webView1);
mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {
            // Handle the error
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

mWebView.loadUrl("http://google.com");

This won't open other broweser. Have reference here from DEVELOPER's SITE.

这篇关于"完成动作用"想在web视图加载时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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