Simple Application Using Android Web View

Appportunity

Build your own Android App Dev Empire

Get Instant Access

This section shows how to embed a WebView, which could allow you to add HTML UI to your native Android application. Create a project, as you did in the previous tutorial (Figure 3-15).

Figure 3-15. Create Project.

In this example, we don't use a layout (although you could). Instead, we simply create a new WebView and then set the ContentView to that instance of the WebView. Then we dynamically create some html and load it into the WebView (Figure 3-16). This is a very simply example of a powerful concept (Figure 3-17).

package sample.webview;

import android.app.Activity; import android.os.Bundle; import android.webkit.WebView;

package sample.webview;

import android.app.Activity; import android.os.Bundle; import android.webkit.WebView;

public class SampleWebView extends Activity {

/** Called when the activity is first created. */ ^Override public void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState); WebView webview - new WebView(this); setContentView(webview);

String hello - "<html><body><p>This could be HTML UI</p></body></html>";| webview.loadData(hello, "text/html", "utf-8");

Figure 3-16. Code for adding a WebView to SampleWebView.java

Figure 3-16. Code for adding a WebView to SampleWebView.java

Figure 3-17. Application with WebView running in the Android simulator

For more details on different ways to use WebView in Android, see http://developer.android.com/reference/android/webkit/WebView.html.

Was this article helpful?

0 0
iPhone and iPad App Cash

iPhone and iPad App Cash

Discover how a single application could generate $1000's of dollars, instantly. The simple, low cost system for outsourcing app development to freelancers. How to quickly evaluate applications so you can create a high profit one of your very own. The fastest way to leverage the popularity of iPhone and iPad apps to skyrocket your income. Top methods for promoting your application for maximum exposure.

Get My Free Ebook


Post a comment