加载网页中的WebView在android系统?加载、网页、系统、WebView

2023-09-06 19:28:18 作者:笙歌白云上

我有一个链接,例如http://google.com,我需要在我无论是在网络视图或其他视图的应用程序加载网页,而不是在android系统的默认浏览器,无论是是可能的,或者不

i have a link for example,"http://google.com" , i need to load the web page in to my app either in web view or some other View, but not in default Browser of android , whether it is possible or not.

感谢

推荐答案

我想你想在应用程序内的WebView中的负载网址。如果我没看错的话,你可以有:

I think you want to load URL in webview within the application. If i am not wrong, then you can have:

WebView browser = (WebView)findViewById(R.id.browser);
browser.setWebViewClient(new WebViewClient() {
    /* On Android 1.1 shouldOverrideUrlLoading() will be called every time the user clicks a link,
     * but on Android 1.5 it will be called for every page load, even if it was caused by calling loadUrl()! */
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        /* intercept all page load attempts and load yahoo.com instead */
        String myAlternativeURL = "http://yahoo.com";
        if (!url.equals(myAlternativeURL)) {
            view.loadUrl(myAlternativeURL);
            return true;
        }

        return false;
    }
});

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

和一般情况下,你也可以使用 webview.loadURL(URL) 方法来加载URL的网页视图。

And In general, you can also use webview.loadURL(URL) method to load URL in webview.