Suppose we want to provide a Web application (or just a Web page) as part of a client application, we can use WebView. The WebView class is an extension of the Android view class, which agrees to show you a portion of the active layout of a Web page.
It does not contain any features of a fully developed web browser, such as navigation controls or an address bar. All WebView, by default, displays a Web page.
WebView What is the application scenario, we can use WebView to display some information, such as you may need to update, such as an end user agreement or user Guide. In your Android app, you are able to create a acitivity including WebView. Then use to display the online documents you host.
There is also a scenario in which WebView can help assume that your application provides data to the user, always requiring a network connection to retrieve data, such as e-mail. In such cases, you may find that creating a WebView in an Android application displays a Web page displaying all the user data instead of running a network request, then parsing the data and presenting it to an Android layout that is now easy.
Calls to WebView have procedures such as those seen below
(1)
Add the WebView control to your application by simply including the layout of the < WebView > elements in the activity.
<?xml version= "1.0" encoding= "Utf-8"? ><webview xmlns:android= "http://schemas.android.com/apk/res/ Android " android:id=" @+id/webview " android:layout_width=" fill_parent " android:layout_height=" Fill_ Parent "/>
(2)
Use Loadurl () to load a webview.
WebView Mywebview = (WebView) Findviewbyid (R.id.webview); Mywebview.loadurl ("http://www.example.com");
(3)
Join a network license in a manifest file
<manifest > <uses-permission android:name= "Android.permission.INTERNET"/> ... </ Manifest>
About JavaScript
Assuming you plan to use JavaScript on your load Web page WebView, you must enable JavaScript WebView. Once JavaScript is enabled, you can also create an interface between your application code and JavaScript code.
JavaScript is disabled by default in WebView. You can make it by attaching websettings to him. You can retrieve the GetSettings websettings () and then use setjavascriptenabled to enable JavaScript ().
WebView Mywebview = (WebView) Findviewbyid (R.id.webview); WebSettings websettings = Mywebview.getsettings (); websettings.setjavascriptenabled (true);
About historical return
When your WebView rewrite URL is loaded, it will proactively accumulate its own historical access to the Web page. You can navigate backwards and forwards to historical GoBack () and GoForward ().
@Overridepublic boolean onKeyDown (int keycode, keyevent event) { //Check If the key event is the back button and if There ' s history if ((keycode = = keyevent.keycode_back) && mywebview.cangoback ()) { mywebview.goback () ; return true; } If It wasn ' t the back key or there's no Web page history, bubble up to the default //system behavior (probably Exi t the activity) return Super.onkeydown (KeyCode, event);}
Development and use of Android WebView (source sharing)