Android Development _ about WebView when using links to display problems when invoking the browser

Source: Internet
Author: User

In our actual development, we use WebView to show the effect of the specified page in one part of our app.

But in the course of learning, I found a problem:

Some Web pages use the WebView control to display, then click on a link in the page, go to the next page, it does not continue to display in the app, but to display the URL in the mobile browser, which shows that there is no good human-computer interaction experience. (PS: Some pages of this problem does not appear, I do not have a lot of tests, it is estimated that I use the webview in fragment, in the activity there is no such problem, no matter what, plus the corresponding code can be)

Let's look at the code

1 Package Com.example.qunxiong;2 3 import Android.os.Bundle;4 import android.support.v4.app.Fragment;5 import Android.view.LayoutInflater;6 import Android.view.View;7 import Android.view.ViewGroup;8 import android.webkit.WebSettings;9 import Android.webkit.WebView;Ten import android.webkit.WebViewClient; One  A  Public classFragmentshow extends fragment{ -     PrivateWebView WebView; - @Override the      PublicView Oncreateview (layoutinflater inflater, ViewGroup container, - Bundle savedinstancestate) { -         //TODO auto-generated Method Stub -      +          -          +         returnInflater.inflate (R.layout.web_show, container,false); A     } at @Override -      Public voidonviewcreated (view view, Bundle savedinstancestate) { -         //TODO auto-generated Method Stub - super.onviewcreated (view, savedinstancestate); -WebView =(WebView) View.findviewbyid (R.id.webview); -WebSettings settings =webview.getsettings (); inSettings.setjavascriptenabled (true); -         //set up a link to open a URL within the app toWebview.setwebviewclient (Newwebviewclient ()); +          -         //Support Scaling theSettings.setusewideviewport (true);//Set Support viewport *Settings.setloadwithoverviewmode (true); $Settings.setbuiltinzoomcontrols (true);Panax NotoginsengSettings.setsupportzoom (true);//Set Support Zoom -          the         //Open URLs +Webview.loadurl ("http://www.527fgame.com/news.html"); A     } the     //set up a link to open a URL within the app +     classWebviewclient extends webviewclient{ - @Override $          PublicBoolean shouldoverrideurlloading (WebView view, String URL) { $             //TODO auto-generated Method Stub - view.loadurl (URL); -             return true; the         } -     }Wuyi}

The code is simple, and it gives the appropriate comments.

Where the key code

1 // set up a link to open a URL within the app 2         Webview.setwebviewclient (new webviewclient ());
1 //set up a link to open a URL within the app2     classWebviewclient extends webviewclient{3 @Override4          PublicBoolean shouldoverrideurlloading (WebView view, String URL) {5             //TODO auto-generated Method Stub6 view.loadurl (URL);7             return true;8         }9}

Plus, there's no problem with the Web page appearing in the browser.

Android Development _ about WebView when using links to display problems when invoking the browser

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.