Recently used WebView to load the URL Display Web page in the app, by pasting a simple example.
For general applications, there is no need for complex processing logic when it comes to displaying Web pages, but the novice may encounter a problem with the process: (Daniel can ignore it)
1, call the Webview.loadurl () method, will still invoke the system browser;
2. Press the Back button to exit the interface directly instead of returning to the previous level of the open Web page.
In fact, if only a simple display of the Web page, just a bit
1, to WebView set their own definition of webviewclient;
2. Cover the Shouldoverrideurlloading method in Webviewclient ().
At this point, the first problem has been resolved, no longer invoke the phone's own browser, and implemented within the application to open the link display.
3, covering the activity OnKeydown method, from which to determine whether the Web page can return to the previous page, if there is no return to the previous page, the activity return key logic.
After completing these three parts, the simple use of webview can be achieved. If you need more complex processing, such as executing JS code to call the phone or other more advanced functions, please do further research.
On the code:
public class Publicwebviewactivity extends Baseactivity{private WebView WebView; @Overrideprotected void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_public_webview); WebView = (WebView) Findviewbyid (R.id.webview);//Use the custom Webviewclientwebview.setwebviewclient (new Webviewclient () {/ /Overwrite Shouldoverrideurlloading method @overridepublic Boolean shouldoverrideurlloading (WebView view, String URL) { View.loadurl (URL); return true;}); Webview.loadurl (URL);} Overwrite onKeyDown add processing WebView interface returns event Handling @overridepublic boolean onKeyDown (int keycode, keyevent event) {if (keycode = = Keyeven T.keycode_back && Webview.cangoback ()) {webview.goback ();//Return to previous page return true;} Return Super.onkeydown (KeyCode, event);}}
WebView Basic Application Example--android using WebView to open a Web page within an app