Android Development and Use of WebView (source code sharing)

Source: Internet
Author: User

If we want to provide a web application (or just a web page) as part of the client application, we can use WebView. The WebView class is an extension of the Android View class. It allows you to display some of the Active la s on the web page. It does not include any fully developed web browser features, such as navigation controls or an address bar. All webviews are displayed on a web page by default.

What are the application scenarios of Webview? We can use WebView to display and provide some information. For example, you may need to update it, such as an end-user protocol or user guide. In your Android Application, you can create an Acitivity containing WebView. And then use it to display the online documents you host. In another scenario, WebView always requires a network connection to retrieve data, such as email, if your application provides data to users. In this case, you may find that creating a WebView shows all user data on a web page of the Android application, rather than executing a network request, it is easy to parse the data and present it in an Android layout. Some steps to call WebView are as follows:

(1)

Add the WebView control to your application. You only need to include the Layout of the <WebView> element in the activity.

 
 

(2)

Use loadUrl () to load a WebView.

WebView myWebView = (WebView) findViewById(R.id.webview);myWebView.loadUrl("http://www.example.com");

(3)

Add network authorization in the configuration file

     
      ...
 

If you plan to use JavaScript in WebView on the web page of your load, you must enable JavaScript WebView. Once JavaScript is enabled, you can also create interfaces between your application code and JavaScript code. JavaScript is disabled by default in WebView. You can enable WebSettings. You can search for WebSettings () with getSettings, and then enable JavaScript () with setJavaScriptEnabled ().
WebView myWebView = (WebView) findViewById(R.id.webview);WebSettings webSettings = myWebView.getSettings();webSettings.setJavaScriptEnabled(true);


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.