shouldOverrideUrlLoading返回方法方法、shouldOverrideUrlLoading

2023-09-06 10:30:56 作者:凝安

我用这方法 - 并返回真正 super.shouldOverrideUrlLoading(查看URL); 我的道歉太天真,但我不明白的是什么返回true或超类方法有什么区别?

  @覆盖        公共布尔shouldOverrideUrlLoading(的WebView视图,字符串URL){            UltimatixTouchWebView web视图=(UltimatixTouchWebView)视图。            如果(零=网址&放大器;!及((url.endsWith()|| url.endsWith()))JS。的CSS。                    &功放;&安培; (checkResource(URL))){                返回true;            }其他{                返回super.shouldOverrideUrlLoading(查看,网址);            }        } 

解决方案

我花了一些时间,做了所有的scenerios一些置换。这是我发现 -

返回false - >如果你使用这个,你甚至都不需要加载的URL,即没有必要把使用loadURL(URL)的WebView 将自动加载的网址。

返回true - >当前URL不会在的WebView加载,引用的 Android的网站

  

如果提供WebViewClient,返回true表示主机应用程序处理的URL

所以,你的应用程序将处理它。 IE浏览器。您的应用程序必须有一些功能上的网址工作。即使你只需要加载页面回到你的的WebView ,你将不得不写 webView.loadUrl(URL); 。否则,将不会加载页面。

Python 单例

在这个例子中,假设你想要去的从第一页到second.html。

 公共布尔shouldOverrideUrlLoading(的WebView视图,字符串URL){                如果(url.contains(second.html)){                    Toast.makeText(CON,第二页,Toast.LENGTH_LONG).show();                    view.loadUrl(URL);                    }                返回true;} 

在这里,如果你点击第二页上的任何链接,也不会去任何地方。因为在这个功能你的如果条件不满足,则返回真正所以它会看到,如果应用程序已经实现的东西。由于我们没有,所以它会呆在那里只。

我试图简化它助阵新的开发人员。

I am using this method - and returning true or super.shouldOverrideUrlLoading(view,url); my apologies for being naive but I didn't understand what is the difference in returning true or the super class method?

 @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            UltimatixTouchWebView webView = (UltimatixTouchWebView) view;

            if (null != url && ((url.endsWith(".js") || url.endsWith(".css")))
                    && (checkResource(url))) {
                return true;
            } else {
                return super.shouldOverrideUrlLoading(view, url);
            }
        }

解决方案

I spent some time and did some permutation on all the scenerios. This is what I found -

return false -> if you use this, you don't even need to load the url, ie no need to put loadUrl(url). WebView will automatically load url.

return true -> Current URL will not be loaded in WebView, Quoting the Android site

If WebViewClient is provided, return true means the host application handles the url

So, your app will handle it. ie. your app has to have some functionality to work on that url. Even if you only want to load the page back in your WebView, you will have to write webView.loadUrl(URL);. Otherwise it will not load your page.

In this example, suppose you want to go to second.html from first page.

public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if(url.contains("second.html")){
                    Toast.makeText(con, "Second Page", Toast.LENGTH_LONG).show();
                    view.loadUrl(url);
                    }
                return true;
}

Here, if you click any link on second page, it will not go anywhere. Because in this function your if condition does not fulfill, it returns true so it will see if app has implemented something. Since we have not, so it will stay there only.

I tried to simplify it to help out new developers.