How to make a transparent WebView in Android

Published by Igor Khrupin on

Today one of my subscribers (@prasad) ask me: “how to make a transparent webview behind a gridview.”

I don’t have complete example for it, but this info might help you.

Do do transparent WebView I create this layout:

<?xml version="1.0" encoding="UTF-8"?>
<!--?xml version="1.0" encoding="utf-8"?-->
<linearlayout xmlns:android="" 
   <webview android:id="@+id/webView1" 
            android:layout_height="match_parent" />

Notice, that backgroung behind WebView is RED

And here I have sourcecode of Activity:

package com.hrupin.transparent_webview;

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

public class Transparent_webviewActivity extends Activity {
    private WebView webview;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        webview = (WebView) findViewById(;
        // Here is I make transparent background for WebView
        String summary = "<h1>The content of the document......</h1>";
        webview.loadData(summary, "text/html", null);

That’s all.
It works for me on Android 2.3.3 (Gingerbread). Device is HTC Desire.

1 Comment

prasad · 9 August, 2012 at 11:47

thanks bro the thing is that when i click on the button gridview in coming ..above the webview but when i again click on the same button gridview dissappear but that space is occupied…i want gridview to dissappear but the webview should occupy whole page then plz help bro iam stuck here

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.