2013年7月10日 星期三

WebView

WebView class provides you ways to embed a web application or a web page as part of a client application. Binding JavaScript code and Android code is also doable through WebView, which provides a way for host application to control some of the features in client application. The following is the typical layout and use of WebView:

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>
--- 
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl(url); 
 
JavaScript is disabled by default for WebView. We can enable it by doing the following:
 
 WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true); 
 
When you're designing your own web application, you can create interfaces between your JavaScript 
code and client-side Android code. The idea is that you create a class as well as a public method in 
your Android application which then can be used by JavaScript code in web application. 
Find the reference links for more details.

Reference links
http://developer.android.com/guide/webapps/webview.html 

沒有留言:

張貼留言