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"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="#ff0000">

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

Notice, that backgroung behind WebView is RED

And here I have sourcecode of Activity:

package com.hrupin.transparent_webview;

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

public class Transparent_webviewActivity extends Activity {
    private WebView webview;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        webview = (WebView) findViewById(R.id.webView1);
        // Here is I make transparent background for WebView
        webview.setBackgroundColor(0x00000000);
        String summary = "<html><head><title>Title of the document</title></head><body><h1>The content of the document......</h1></body></html>";
        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

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.