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: