Android Base controls use details--webview

Source: Internet
Author: User

In the development of often inexplicable problems, make a record, convenient to summarize later, the series will not be updated regularly!


WebView is a component of Android and its kernel is based on the open source WebKit engine. If we do some beautification and packaging of the webview, we can develop our own browser very easily.


1, prohibit hyperlinks when the call to other browsers

Today invoke Web page display control, a set of carousel diagram, according to the server returned by the URL to do the Web page display, the same format, some can normally open in WebView, some will be inexplicably pop up the browser selection box. Very depressed!

Search a bit, find the solution, two steps, as follows:

Step1: First, the page control initialization section

String URL = getintent (). Getstringextra ("url"); WebView WebView = (WebView) Findviewbyid (R.id.webview); Webview.loadurl (URL);//If you want to click on the link to handle it yourself, Instead of the new Android system browser should be linked in the ring. You need to add an Event listener object (webviewclient) to WebView and override the Shouldoverrideurlloading method Webview.setwebviewclient (New Mywebviewclient ());

Step2: Adding a Listener object

Private class Mywebviewclient extends Webviewclient {public Boolean shouldoverrideurlloading (WebView view, String URL) {V Iew.loadurl (URL);  return true;};}

2. Scroll bar Settings

Webview.sethorizontalscrollbarenabled (TRUE);//Set the horizontal scrollbar, true to allow the use of webview.setverticalscrollbarenabled (false);// Sets the vertical scroll bar  , false to prohibit the use of the

3. When the screen switch is forbidden, reload the webpage

Need to add android:configchanges= "Keyboardhidden|orientation|screensize" in Androidmanifest.xml

4. Turn on JavaScript support

Webview.getsettings (). Setjavascriptenabled (true);//Turn on JavaScript support

5. settings can automatically load pictures

Webview.getsettings (). Setloadsimagesautomatically (true);//settings can automatically load pictures


Android Base controls use details--webview

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.