Android uses WebView to load and display Web content, first defined in the layout file WebView
<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:app= "Http://schemas.android.com/apk/res-auto"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"App:layout_behavior= "@string/appbar_scrolling_view_behavior"Tools:context= "Cn.com.buynow.jspot.MainActivity"Tools:showin= "@layout/app_bar_main"> <WebViewAndroid:id= "@+id/webview"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"></WebView></Relativelayout>
The activity code, using the Webview.loadurl () method to load the page, is very simple.
You can also set some properties, such as whether to use JavaScript scripts, whether to use caching, and so on.
protected voidLoadurl (String params) {WebView= (WebView) This. Findviewbyid (R.id.webview); Webview.loadurl (Product_query_uri+params); WebSettings Settings=webview.getsettings (); Settings.setappcacheenabled (false); Settings.setjavascriptenabled (true); Webview.setwebviewclient (Newwebviewclient () {@Override Public Booleanshouldoverrideurlloading (WebView view, String URL) {view.loadurl (URL); return true; } }); Webview.setwebchromeclient (Newwebchromeclient () {@Override Public voidOnprogresschanged (WebView view,intnewprogress) { if(newprogress = = 100) { //Load Complete}Else { //Load in } } }); }
The settings are implemented by the WebSettings class
WebSettings settings = webview.getsettings (); Settings.setappcacheenabled (false); Whether to enable cache settings.setjavascriptenabled (true); Whether JavaScript is enabled
Android uses WebView to load Web pages