Android basic control usage details-WebView

Source: Internet
Author: User

Android basic control usage details-WebView

Some inexplicable problems often occur during development. Make a record to facilitate future summarization. This series will be updated from time to time!


WebView is a component of android, and its kernel is based on the open-source WebKit engine. If we beautify and package WebView, we can easily develop our own browser.


1. Call other browsers to disable hyperlinks

Today, the webpage display control is called. A set of carousel images are displayed based on the URL Connection returned by the server. In the same format, some images can be opened in WebView normally, some will pop up the browser selection box inexplicably. Very depressing!

After searching, find the solution and perform the following two steps:

Step 1: Initialize the Page Control

String url = getIntent (). getStringExtra ("url"); WebView webview = (WebView) findViewById (R. id. webView); webview. loadUrl (url); // if you want to click the link, you can handle it by yourself, instead of clicking the link in the browser of the new Android system. // Add an event listening object (WebViewClient) to WebView, and rewrite the shouldOverrideUrlLoading method webview. setWebViewClient (new MyWebViewClient ());

Step 2: Add a listener object

private class MyWebViewClient extends WebViewClient { public boolean shouldOverrideUrlLoading(WebView view, String url) {view.loadUrl(url);  return true;};}

2. scroll bar settings

Webview. setHorizontalScrollBarEnabled (true); // sets the horizontal scroll bar. true indicates that webview. setVerticalScrollBarEnabled (false) is allowed; // sets the vertical scroll bar. false indicates that the horizontal scroll bar is disabled.

3. Disable page loading when switching between landscape and portrait screens

Android: configChanges = "keyboardHidden | orientation | screenSize" must be added to AndroidManifest. xml"

4. Enable Javascript support

Webview. getSettings (). setJavaScriptEnabled (true); // enable Javascript support

5. set to automatically attach Images

Webview. getSettings (). setLoadsImagesAutomatically (true); // You can automatically load images.


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.