In the past, hackers used web pages for the speed edition and the network shield client. So I have a special liking for this mode. The webview component in android carries the webkit kernel, V8 script engine, and HTML5. If you use this to create some online application interfaces, it should be a good choice. Although the android writing interface is already quite simple (compared to the painful memory of writing a GUI using Java Swing five years ago), online web pages naturally offer online benefits. In addition, HTML5's offline storage function is also good. I spoke a bunch of nonsense. Sorry.
First, create a project and use the webview component.
Demo code core:
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
MWebView = (WebView) this. findViewById (R. id. webview );
MHandler = new Handler ();
WebSettings webSettings = mWebView. getSettings ();
WebSettings. setJavaScriptEnabled (true );
MWebView. addJavascriptInterface (new Object (){
Public void clickOnAndroid (){
MHandler. post (new Runnable (){
Public void run (){
MWebView. loadUrl ("javascript: wave ()"); // call the Script Function
}
});
}
}, "Demo"); // provides an interface for the script function, window. demo. clickOnAndroid ()
MWebView. loadUrl ("file: // android_asset/html/notice.html ");
Note the following points:
(1) If the application needs to access the Internet, add the following to AndroidManifest. xml:
<Uses-permission android: name = "android. permission. INTERNET"/>
(2) In the code, android_asset is equivalent to the resources under the assets directory in the project path.
(3) setJavaScriptEnabled is used to set whether javascript scripts are allowed and must be enabled.
(4) In main. xml under layout, <WebView android: id = "@ + id/webview" android: layout_width = "fill_parent" android: layout_height = "wrap_content"/>
This demo is successfully completed. There are two main points in this demo: 1. Use the webpage as the interface, 2. Mutual calls between JavaScript and Java are implemented.
Author-274 °C