Android Project---WebView

Source: Internet
Author: User

Before using WebView, only know that it can be loaded out of the HTML page, it is not known, it can also interact with JS.

WebView is a network view that can load a display page and can be viewed as a browser. It uses the WebKit rendering engine to load the Display Web page

In Andriod, many controls are available in two ways, one is instantiated in a Java file, and one is declared in a layout file

Steps for the first method:
1. Instantiate the WebView component in the activity to: WebView WebView = new WebView (this);
2. Call WebView's Loadurl () method to set the page to display Wevview:
Internet use: Webview.loadurl ("http://www.google.com");
for local files: Webview.loadurl ("file:///android_asset/XX.html"); Local files are stored in the: Assets file
3. Call the activity's Setcontentview () method to display the page view
4. Use WebView point link to see a lot of pages later in order to let WebView support fallback function, need to overwrite the Activity class onkeydown () method, if do not do any processing, click the system fallback shear key, the entire browser will call finish () and end itself, Instead of retreating back to the previous page
5. You need to add permissions to the Androidmanifest.xml file, or the Web page not available error will occur.
<uses-permission android:name= "Android.permission.INTERNET"/>

Steps for the second method:
1. Declare webview in the layout file
2, in the activity of the instantiation of WebView
3, call WebView Loadurl () method, set Wevview to display the page
4. To enable WebView to respond to hyperlinks, call the Setwebviewclient () method to set the WebView view
5, with WebView point link to see a lot of pages later in order to let WebView support fallback function, need to overwrite the Activity class onkeydown () method, if do not do any processing, click the system fallback shear key, the entire browser will call finish () and end itself, Instead of retreating back to the previous page
6. You need to add permissions to the Androidmanifest.xml file, or the Web page not available error occurs.
<uses-permission android:name= "Android.permission.INTERNET"/>

---------------------------------------------------------------------------------------------

And there's the problem of solving webview adaptive screens.

If parsing with an HTML class does not exist this problem, but, WebView can make the text adaptive, the picture is easy to overflow, so that the screen appears horizontal scroll bar

         settings.setusewideviewport (true);         Settings.setloadwithoverviewmode (true

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.