Android uses WebView to load Web pages

Source: Internet
Author: User

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

Related Article

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.