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.