Use of Android UI WebView:

Source: Internet
Author: User

Use of Android UI WebView:

/**
* @author Smiling
* @date 2016/10
*/

Layout:


<?xml version= "1.0" encoding= "Utf-8"?>
<webview
Android:id= "@+id/webview"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"/>

If you want to load a page with JavaScript, you must make JavaScript available for your webview.
Mvewview.getsettings (). Setjavascriptenabled (True);
Zoom, set to not scale icon to prevent zooming in and out on the page
Mvewview.getsettings (). Setbuiltinzoomcontrols (false);
Cache
Mvewview.getsettings (). Setcachemode (Websettings.load_no_cache);
Turn on DOM Storage API functionality
Mvewview.getsettings (). Setdomstorageenabled (True);
Turn on the application cache function
Mvewview.getsettings (). setappcacheenabled (false);
Page reaction without invoking a third-party browser
Mvewview.setwebviewclient (New Webviewclient () {
@Override
public boolean shouldoverrideurlloading (WebView view, String URL) {
Mvewview.loadurl (URL);
return true;
}

@Override
public void onpagefinished (WebView view, String URL) {
super.onpagefinished (view, URL);
Progressdialog.dismiss ();
}
});

Mvewview.loadurl ("http://www.google.com");

Mvewview.loadurl ("file:///android_asset/XX.html");

String htmlstring = "Load this HTML page
Mywebview.loaddata (htmlstring, "text/html", "utf-8");

GoBack () and GoForward (): When your webview overwrite the URL loading behavior, it automatically accumulates a history of the pages visited;

/**
* Key response, when viewing the page in WebView, press the Back button to return by browsing history,
* If this process is not done then the entire webview returns to exit
*/
@Override
public boolean onKeyDown (int keycode, keyevent event)
{
Check If the key event is the back button and if there's history
if ((keycode = = keyevent.keycode_back) && mywebview.cangoback ())
{
Return key Bounce
Mywebview.goback ();
return true;
}
If It wasn ' t the back key or there's no Web page history, bubble up
to the default
System behavior (probably exit the activity)
Return Super.onkeydown (KeyCode, event);
}

Use of Android UI 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.