Skip to Navigation | Skip to Content



Android Webkit Tutorial | October 8th, 2008

Recently, I’ve been playing with the Android SDK. The main thing that has me pumped about Android is the fact that it’s open and the fact that I can actually write code for it without having to get a Mac and run Mac OS X. I’ve been messing around with it a couple weeks, and I found that there wasn’t a good set of code samples for developing with Android.

So, here’s a rough description of what you need to do to get a WebView to actually be useful in Android. First of all, you should already be familiar with the basics, since we’re not going to be spending too much time on them here. You need to use the following in the layout:

            < WebView android:id="@+id/appView"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent" />

This should be in a layout element in your XML Layout. I use the Linear Layout similar to the tutorial, but you may want to use a different layout. Then, I started using it with the following Java code:

WebView appView;
appView = (WebView) findViewById(R.id.appView);
appView.getSettings().setJavaScriptEnabled(true);
appView.loadUrl("http://www.nitobi.com");

This code should be put in the onCreate method of the activity, since this will be loaded at the beginning of the activity. This is the most basic way to make sure that you get a full running browser. It’s something that I didn’t find straight forward from the API docs, so I figured that I’d pass this thing on. It’ll be a while since I’ll be getting one of these phones, since I’m in Canada, but I have a feeling that this will be coming up again very soon.

Posted in Uncategorized | 4 Comments » | Add to Delicious | Digg It

This entry was posted on Wednesday, October 8th, 2008 at 6:04 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

4 Responses to “Android Webkit Tutorial”

  1. James Says:

    There is no code for the layout… Can you please provide it?

  2. Joe B Says:

    Here it is. Unfortunately, we haven’t gotten the code preview app to work the way that I would like.

  3. Smita Says:

    Hello,
    I had able to run the browser but I have to open certified sites but I can’t. Can anybody help me.
    Thks in advance.

  4. Abhinav Narain Says:

    Just take the uncommented portion. Look carefully , i havent used websetting at all .
    I will open the

    WebView webview;
    /*String htmldata = “Time to play the game CodeMan Abhinav Narain , IIT M “;
    final String mimetype = “text/html”;
    final String encoding = “UTF-8″;*/
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    webview = (WebView) findViewById(R.id.webview);
    // webview.setWebViewClient(new HelloWebViewClient());
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl(“http://www.google.com”);

    }

Leave a Reply