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